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()
Related
I'm a student learning VB.NET.
I get "Function ToString doesn't return a value on all code paths"
on a overrides function?
and it does not work the way it should.
There is a combobox(Label11 references), that selects the way the listbox layout is.
Here is the code that i have the problem with, any help will be appreciated.
Overrides Function ToString() As String
Try
If _label11 = "" Then
Return _contactName & " - " & _SurName & vbTab & "(" & _companyName & ")" & vbTab & _state & vbTab & _email
Else
If _label11 = "Name" Then
Return _contactName & " - " & _SurName & vbTab & "(" & _companyName & ")" & vbTab & _state & vbTab & _email
Else
If _label11 = "Surname" Then
Return _SurName & " - " & _contactName & vbTab & "(" & _companyName & ")" & vbTab & _state & vbTab & _email
Else
If _label11 = "Company Name" Then
Return "(" & _companyName & ")" & vbTab & _contactName & " - " & _SurName & _state & vbTab & _email
Else
If _label11 = "Product" Then
Return _state & vbTab & "(" & _companyName & ")" & vbTab & _contactName & " - " & _SurName & _state & vbTab & _email
End If
End If
End If
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
Finally
End Try
End Function
Here is what I have now,
It seems that the cmbSelect combobox does not send the info from my form2 to the contact class.
I have googled and tried everything to get it to work?
With the current one it gives an error"Object reference not set to an instance on an object"
Any idees?
Overrides Function ToString() As String
Select Case cmbSelect.SelectedIndex
Case 0
Return _contactName & " - " & _SurName '& vbTab & "(" & _companyName & ")" & vbTab & _state & vbTab & _email
Case 1
Return _contactName & " - " '& _SurName & vbTab & "(" & _companyName & ")" & vbTab & _state & vbTab & _email
Case 2
Return _SurName '& " - " & _contactName & vbTab & "(" & _companyName & ")" & vbTab & _state & vbTab & _email
Case 3
Return "(" & _companyName & ")" ' & vbTab & _contactName & " - " & _SurName & _state & vbTab & _email
Case 4
Return _state & vbTab '& "(" & _companyName & ")" & vbTab & _contactName & " - " & _SurName & _state & vbTab & _email
Case Else
Return _contactName & " - " & _SurName & vbTab & "(" & _companyName & ")" & vbTab & _state & vbTab & _email & vbTab & _NumId
End Select
End Function
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
I am creating a loan amortization table using Vb.net. All working fine but my loop is not working correctly. It should show all the reducing monthly payments, balance one after another. My code for loop is given below:
Listbox1.Items.Add("Nos" & vbTab & "Periodic" & vbTab & "Payment" & vbTab & "Payment" & vbTab & "Balance")
Listbox1.Items.Add("" & vbTab & "Payment" & vbTab & "Interest" & vbTab & "Principal" & vbTab & "")
Listbox1.Items.Add("__________________________________________________________________________________________")
Dim a As Integer
**For a = 1 To n
monthly_Interest = (p * (txtbox_Rate.Text / 100) * (1 / 12))
monthlyPrincipal = monthlyPayments - monthlyInterest
balance = p - monthlyPrincipal
Listbox1.Items.Add(a & vbTab & FormatCurrency(monthlyPayments, 2) & vbTab & FormatCurrency(monthly_Interest, 2) & vbTab & FormatCurrency(monthlyPrincipal, 2) & vbTab & FormatCurrency(balance, 2))
Next**
I am doing a project to generate a Microsoft word document. My code as follows. Im getting exception as "System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
at reportexample.Form1.GetNewResult(Field wField, Document WordDoc) in F:\reportexample\reportexample\Form1.vb:line 114"
Private Function GetNewResult(wField As Word.Field, WordDoc As Word.Document) As String
Dim StopPos As Long
Dim Variable As String = ""
Dim UsedVariable As String
Dim VariableValue As String
Dim wRange As Word.Range
Try
Debug.Print(wField.Code)
' These three lines strip down the field code to find
' out it's name
StopPos = InStrRev(wField.Code, "\*")
Variable = Microsoft.VisualBasic.Left(wField.Code, StopPos - 3)
Variable = Microsoft.VisualBasic.Right(Variable, Len(Variable) - 14)
Catch ex As Exception
TextBox1.Text = ex.ToString
End Try
' Check this field hasn't already appeared in this
' document.
If CheckUsedVariable(Variable) Then
VariableValue = GetVariableValue(Variable)
Else
Select Case UCase(Variable)
' I don't simply want to insert a string -
' I wish to insert a table at the Product Field.
Case "PRODUCT"
' Get the range (location) of the product field
wRange = wField.Code
' Delete the field, as any text will be inserted into the
' {} of the existing field.
wField.Delete()
' Enter our table information including headers.
' Ideally, I would get this data from an ADO recordset
' using GetString().
With wRange
.Text = "PRODUCT" & vbTab & "CTSBATCHNO" & vbTab & "SUPP REF" & vbTab & "PACKNO" & vbTab & "STORAGE" & vbTab & "QTY UNITS" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3" & vbCrLf & _
"989797897" & vbTab & "hjhkhk" & vbTab & "kjhkjhkh" & vbTab & "kjhkjh" & vbTab & "Frozen" & vbTab & "3"
.FormattedText.Font.Name = "Arial"
.FormattedText.Font.Size = "8"
' Once the data is there, we can convert it to a table
' structure and format it to look pretty!
.ConvertToTable(vbTab, , , , WdTableFormat.wdTableFormatColorful2)
End With
' Send back blank string as field does not exist anymore
VariableValue = ""
Case Else
' Get the value of the field from the user
VariableValue = InputBox("Enter value for: " & Variable, "Value not recognised for Despatch Note!")
AddNewVariable(Variable, VariableValue)
End Select
End If
GetNewResult = VariableValue
End Function
Word.Field.Code
is a Range object which cannot be converted to a string.
Try wField.Code.Text
I just faced a problem with my code.It raises an exception.This is the code.
conn = oSubPayItemDescription.GetDbConnection()
md = New OleDbCommand("SELECT [sub_pay_item_quantity].[quantity],[sub_pay_item_unit_rate].[rate] FROM " &
"[sub_pay_item_quantity],[sub_pay_item_unit_rate] WHERE [sub_pay_item_quantity].[sub item]=[sub_pay_item_unit_rate].[sub item] AND " &
"[sub_pay_item_quantity].[sub item]='" & subItem & "' AND [sub_pay_item_quantity].[bridge type]='" & bridgeType & "' " &
"AND [sub_pay_item_quantity].[span]='" & span & "'", conn)
data_reader = cmd.ExecuteReader()
If data_reader.HasRows = True Then
Do While data_reader.Read()
payItem = CDbl(data_reader.Item("pay item"))
subpayItem = CDbl(data_reader.Item("sub pay item"))
subItem = data_reader.Item("sub item")
unit = data_reader.Item("unit")
bridgeType = data_reader.Item("bridge type")
span = (data_reader.Item("span").ToString())
quantity = CDbl(data_reader.Item("quantity"))
rate = CDbl(data_reader.Item("rate"))
RichTextBox1.AppendText(payItem & vbTab & vbTab & " " & " " & subpayItem & vbTab & vbTab & subItem & vbTab & vbTab & " " & _
unit & vbTab & vbTab & " " & " " & " " & " " & bridgeType & vbTab & vbTab & " " & span & vbTab & _
"" & vbTab & " " & quantity & vbTab & rate & vbNewLine)
Loop
Else
MsgBox("Unit rate does not exist", vbCritical, "Bridge Construction Cost Estimate")
End If
It raises the exception when it reaches the do while loop indicating at pay item.
So the specified name does not exist in the DataReader as the documentation suggests:
IndexOutOfRangeException: No column with the specified name was found
and i cannot see this column in your query. You are selecting only quantity and rate.