Is there a way to Aline to tab, non-fixed-pitch font text in a textbox.
TextBox1.AppendText("Sample text line" & vbTab & vbTab & vbTab & "(100)" & vbNewLine)
TextBox1.AppendText("Sample text line Sample text line" & vbTab & vbTab & vbTab & "(150)" & vbNewLine)
TextBox1.AppendText("Sample text line" & vbTab & vbTab & vbTab & "(200)" & vbNewLine)
I want to aline to two columns those texts using tab char. Can not hardcode vbTab for each line because of texts are dynamically changing.
Related
I am generating an email that shows trades for the day in the body of an email. Currently the only way I can do this is with an If then statement for specific numbers of trades. If we traded 10, I need an if then statement with 10 as the variable criteria, but if I only have 9, then I get an error. I want a dynamic method instead. I can do a For Loop that will list all the trades in debug.print, but in the email, it each trade overwrites the prior trade and I show only one line. I also need an intro like "Hi, today today's trades are: " followed by each trade listed below line by line.
I tried this and it works but only if I have the right number of trades and a variable that matches it. For example, if I had 23 trades, I need an If statement with 23 as a variable value in this case m. I used Arrays as VBA does not let me create a list. Unfortunately, I cannot pull the whole array, I need to pull line by line. If I could pull the array, I could just have a simple loop.
If m = 23 Then
.Body = "Hi Chris," & vbLf & vbLf & "The following trade(s) was completed today:" & vbLf & vbLf & ArrayValues(0) & vbLf & ArrayValues(1) & vbLf & ArrayValues(2) & vbLf & ArrayValues(3) & vbLf & ArrayValues(4) & vbLf & ArrayValues(5) & vbLf & ArrayValues(6) & vbLf & ArrayValues(7) & vbLf & ArrayValues(8) & vbLf & ArrayValues(9) & vbLf & ArrayValues(10) & vbLf & ArrayValues(11) & vbLf & ArrayValues(12) & vbLf & ArrayValues(13) & vbLf & ArrayValues(14) & vbLf & ArrayValues(15) & vbLf & ArrayValues(16) & vbLf & ArrayValues(17) & vbLf & ArrayValues(18) & vbLf & ArrayValues(19) & vbLf & ArrayValues(20) & vbLf & ArrayValues(21) & vbLf & ArrayValues(22) & vbLf & vbLf & "Thanks"
End if
I want to use something like:
For b = 1 To LastRow
If Trades.Range("H" & b) = TDate Then
Debug.Print (Range("B" & b) & " " & Range("C" & b) & " " & Range("D" & b) & " " & Range("F" & b) & " " & Range("G" & b))
End If
Next b
This way it does not matter how may trades I have, one formula would over it all. Each Range has a trade characteristic.
If I do a debug.Print in the immediate window I get a list just like I want, but in the email, each line overwrites the prior trade.
I am a rookie at this and appreciate any help. Thanks
Sounds like you need to build a string which can be assigned to the message body. For such tasks you can use String Functions available in VBA where you can prepare the correct string and then assign to the message body.
If m = 23 Then
.Body = "Hi Chris," & vbLf & vbLf & "The following trade(s) was completed today:" & vbLf & vbLf & ArrayValues(0) & vbLf & ArrayValues(1) & vbLf & ArrayValues(2) & vbLf & ArrayValues(3) & vbLf & ArrayValues(4) & vbLf & ArrayValues(5) & vbLf & ArrayValues(6) & vbLf & ArrayValues(7) & vbLf & ArrayValues(8) & vbLf & ArrayValues(9) & vbLf & ArrayValues(10) & vbLf & ArrayValues(11) & vbLf & ArrayValues(12) & vbLf & ArrayValues(13) & vbLf & ArrayValues(14) & vbLf & ArrayValues(15) & vbLf & ArrayValues(16) & vbLf & ArrayValues(17) & vbLf & ArrayValues(18) & vbLf & ArrayValues(19) & vbLf & ArrayValues(20) & vbLf & ArrayValues(21) & vbLf & ArrayValues(22) & vbLf & vbLf & "Thanks"
End if
Your strategical mistake is that you are trying to set up the Body property for a specific case. Instead, consider concatenating the string with the required piece of data (another string) which makes sense for a particular case. And only when you are done adding all the bits to the result string, you can assign it to the message body.
Be aware, the Body property is a plain text string and doesn't deliver any formatting. Instead, I'd suggest using the HTMLBody property instead. The HTMLBody property should be an HTML syntax string. Setting the HTMLBody property will always update the Body property immediately.
I have a userform that enters data into another userform, with data being entered on a new line for each submission. I am running into a problem where the 1st entered data skips a line on my userform. How can I adjust my code to avoid having the extra white line in the beginning, here is my code:
Private Sub CommandButton1_Click()
opsvision.opsfinding.Value = opsvision.opsfinding.Value & vbNewLine & "Employees" & "---" & generalbuilder.employees.Value & " -" & Space(2) & Space(1) & """" & Me.findings.Value & """" & Space(5) & "----" & Space(3) & "Finding Conducted by: " & Worksheets("userform").Range("B3") & vbNewLine
Unload Me
End Sub
The red line shows the extra white space at the top of the text box
Test to see if it's empty first. Otherwise you concatenate a vbNewLine to the empty starting value:
Private Sub CommandButton1_Click()
Dim line As String
line = "Employees" & "---" & generalbuilder.employees.Value & " -" & Space(2) & _
Space(1) & """" & Me.findings.Value & """" & Space(5) & "----" & Space(3) & _
"Finding Conducted by: " & Worksheets("userform").Range("B3") & vbNewLine
If opsvision.opsfinding.Value = vbNullString Then
opsvision.opsfinding.Value = line
Else
opsvision.opsfinding.Value = opsvision.opsfinding.Value & vbNewLine & line
End If
Unload Me
End Sub
I have the below Excel 2010 VBA that is in two parts. The first portion checks if a CheckBox on a sheet is checked, if it then it adds the value of a specified cell to the sample_descriptor.txt in the portion below that. Currently I am getting a
subscript out of range error
and am not sure if this is the best way to accomplish this task. Thank you :). The value for comment1 is F9, comment2 is F10, comment3 is F11, and comment4 is F12
VBA
' ADD COMMENT IF ANY '
If CheckBox17.Value = True Then
Worksheets("Sheet1").Range("F9") = ActiveSheet.Range("F9").Value
Else
Worksheets("Sheet1").Range("F9") = "No Issues"
End If
If CheckBox17.Value = True Then
Worksheets("Sheet1").Range("F10") = ActiveSheet.Range("10").Value
Else
Worksheets("Sheet1").Range("F10") = "No Issues"
End If
If CheckBox17.Value = True Then
Worksheets("Sheet1").Range("F11") = ActiveSheet.Range("F11").Value
Else
Worksheets("Sheet1").Range("F11") = "No Issues"
End If
If CheckBox17.Value = True Then
Worksheets("Sheet1").Range("F12") = ActiveSheet.Range("F12").Value
Else
Worksheets("Sheet1").Range("F12") = "No Issues"
End If
Unload Me
'WRITE TO SAMPLE DESCRIPTOR.txt '
Open MyDirectory & "sample_descriptor.txt" For Output As #1
Print #1, "Experiment Sample" & vbTab & "Control Sample" & vbTab & "Display Name" & vbTab & "Gender" & vbTab & "Control Gender" & vbTab & "Spikein" & vbTab & "Location" & vbTab & "Barcode" & vbTab & "Medical Record" & vbTab & "Date of Birth" & vbTab & "Order Date"
Print #1, "2571683" & MyBarCode & "_532Block1.txt" & vbTab & "2571683" & MyBarCode & "_635Block1.txt" & vbTab & ActiveSheet.Range("B8").Value & " " & ActiveSheet.Range("B9").Value & vbTab & ActiveSheet.Range("B10").Value & vbTab & ActiveSheet.Range("B5").Value & vbTab & Split(ActiveSheet.Range("B11").Value, " [")(0) & vbTab & ActiveSheet.Range("B12").Value & vbTab & "2571683" & MyBarCode & vbTab & ActiveSheet.Range("C200").Value & vbTab & ActiveSheet.Range("D200").Value & vbTab & ActiveSheet.Range("E200").Value & IIf(Sheet.CheckBox17, vbTab & ActiveSheet.Range("F9").Value, "")
Print #1, "2571683" & MyBarCode & "_532Block2.txt" & vbTab & "2571683" & MyBarCode & "_635Block2.txt" & vbTab & ActiveSheet.Range("C8").Value & " " & ActiveSheet.Range("C9").Value & vbTab & ActiveSheet.Range("C10").Value & vbTab & ActiveSheet.Range("C5").Value & vbTab & Split(ActiveSheet.Range("C11").Value, " [")(0) & vbTab & ActiveSheet.Range("C12").Value & vbTab & "2571683" & MyBarCode & vbTab & ActiveSheet.Range("C201").Value & vbTab & ActiveSheet.Range("D201").Value & vbTab & ActiveSheet.Range("E201").Value & IIf(Sheet.CheckBox17, vbTab & ActiveSheet.Range("F10").Value, "")
Print #1, "2571683" & MyBarCode & "_532Block3.txt" & vbTab & "2571683" & MyBarCode & "_635Block3.txt" & vbTab & ActiveSheet.Range("D8").Value & " " & ActiveSheet.Range("D9").Value & vbTab & ActiveSheet.Range("D10").Value & vbTab & ActiveSheet.Range("D5").Value & vbTab & Split(ActiveSheet.Range("D11").Value, " [")(0) & vbTab & ActiveSheet.Range("D12").Value & vbTab & "2571683" & MyBarCode & vbTab & ActiveSheet.Range("C202").Value & vbTab & ActiveSheet.Range("D202").Value & vbTab & ActiveSheet.Range("E202").Value & IIf(Sheet1.CheckBox17, vbTab & ActiveSheet.Range("F11").Value, "")
Print #1, "2571683" & MyBarCode & "_532Block4.txt" & vbTab & "2571683" & MyBarCode & "_635Block4.txt" & vbTab & ActiveSheet.Range("E8").Value & " " & ActiveSheet.Range("E9").Value & vbTab & ActiveSheet.Range("E10").Value & vbTab & ActiveSheet.Range("E5").Value & vbTab & Split(ActiveSheet.Range("E11").Value, " [")(0) & vbTab & ActiveSheet.Range("E12").Value & vbTab & "2571683" & MyBarCode & vbTab & ActiveSheet.Range("C203").Value & vbTab & ActiveSheet.Range("D203").Value & vbTab & ActiveSheet.Range("E203").Value & IIf(Sheet1.CheckBox17, vbTab & ActiveSheet.Range("F12").Value, "")
Close #1
file format
x
x 1 2 3 4
x 11 22 33 44
x --- --- --- ---
x Male Male Female Male
x --- --- --- ---
x 1 2 3 4 Please check the box to add comment
x 1111 2222 3333 4444 (checkbox17)
x xxx,xxx xxx,xxx xxx,xxx xxx,xxx comment1
x Male Male Female Male comment2
x xx xx xx xx comment3
x x x x x comment4
You must change:
ActiveSheet.Range("10").Value
into:
ActiveSheet.Range("F10").Value
But you can shorten down your code to:
If CheckBox17 Then
Worksheets("Sheet1").Range("F9:F12").value = ActiveSheet.Range("F9:F12").value
Else
Worksheets("Sheet1").Range("F9:F12") = "No Issues"
End If
In my Application i need to display some short notes in label.
So i tried like this
lable1.Text="HELP : " & vbNewLine & vbNewLine & "1. You can Remove or
Replace existing Main Icons" & vbNewLine & vbNewLine _
& "2. If you want to remove any buttons, Right click on Icon and
select UNPIN or select the " _
& " Icon and press delete button from key borad" & vbNewLine &
vbNewLine & "3. Drag the needed button from top menu and drop it on
empty space in Icons." & vbNewLine & vbNewLine & "4. If Reports
having sub reports, You can drag and drop the sub reports only."
If the points in came to second line its start from 2 but i need all letter start same level like this
1 . aaaa
2. bbbbb
vvvvv.
and Help must have underline. How to do it. Can say which control good for this can you give some example also.
am using VB.Net 2008
I dont think you can set tabs in a label, so you might need to manually space the text using a monospaced font. But in a richtextbox, you can do this.
RichTextBox1.Text = "HELP : " & vbNewLine & vbNewLine &
"1." & vbTab & "You can Remove or Replace existing Main Icons" & vbNewLine & vbNewLine &
"2." & vbTab & "If you want to remove any buttons, Right click on Icon and" & vbNewLine _
& vbTab & "select UNPIN or select the Icon and press delete button from keyboard" & vbNewLine & vbNewLine &
"3." & vbTab & "Drag the needed button from top menu and drop it on" & vbNewLine _
& vbTab & "empty space in Icons." & vbNewLine & vbNewLine &
"4." & vbTab & "If Reports having sub reports, You can drag and drop the sub reports only."
RichTextBox1.SelectAll()
RichTextBox1.SelectionTabs = {20}
RichTextBox1.DeselectAll
I have data in dataset which I am loopping to build up data for the email the data is as follows but I am using the following to produce the email using tabs but it doesnt see very iffiencet i can only use plain text is their a better way to get it to format nicer like using the datatable sizes or something
Dim dataForEmail As String = ""
Dim msg As String = ""
msg = "The Following Deliverys where processed for the Following Ordernumbers at " & DateTime.Now.ToString() & Chr(13)
dataForEmail = "Order Number" & vbTab & "BarCode" & vbTab & vbTab & vbTab & "Description" & vbTab & vbTab & vbTab & vbTab & vbTab & "Brand" & vbTab & vbTab & vbTab & "Size" & vbTab & "Colour" & vbTab & "Price" & vbTab & "RRP" & vbTab & vbTab & vbTab & "Qty" & Chr(13)
Dim totalcost As Decimal
If Not IsNothing(results) AndAlso Not IsNothing(results.Rows) _
AndAlso results.Rows.Count > 0 Then
For Each thisRow As DataRow In results.Rows
CreateDeliveryIncFileForGemini(thisRow)
totalcost = totalcost + thisRow.Item("RRPPrice")
dataForEmail = dataForEmail & BuildReportFoEmail(thisRow)
connection.ExecuteNonQuerySql(scriptBuilder.SetDeliveryStatus(2, 1, thisRow.Item("r3DeliveryId")))
Next
connection.ExecuteNonQuerySql(scriptBuilder.SetDeliveryStatus(1, 0))
dataForEmail = dataForEmail & vbCrLf & "Total Price " & totalcost.ToString()
SendEmailViaWebService(dataForEmail, cfb.EmailForDeliverys, cfb.FullNameForEmailSubject, msg)
End If
CloseConnection()