Howdy Folks,
With the following code, the IF Statement doesn't compare the two strings. It assigns the value of mainPartNum to Me.PartsDataSet........etc.
I only have 20 rows of data and twenty part numbers 5900001 to 5900020. If I put 5900088 in the TextBox, that same number is assigned to the Me.PartsDataSet.Part_Numbers(i).PartNumber and I get a match = true.
I viewed the values with a MessageBox. Whatever I type into the txtMainPartNum TextBox shows as the same number for Me.PartsDataSet.Part_Numbers(i).PartNumber.
Why is the If Statement not comparing the two strings
Thanks for some input!
Dim
match As Boolean = FalseDim
rowCount As Integer = Me.PartsDataSet.Part_Numbers.Rows.Count Dim mainPartNum = txtMainPartNum.Text For i = 0 To rowCount - 1 If mainPartNum = Me.PartsDataSet.Part_Numbers(i).PartNumber Thenmatch =
True Exit For End If Next

Bug In VB Express If Statement?
LN42
I just tried
Sub Main() Dim match As Boolean = False Dim rowCount As Integer = 5 Dim mainPartNum = "7" Dim i As Integer For i = 0 To rowCount - 1 If mainPartNum = "8" Thenmatch =
True Exit For End If Next
End Suband it worked fine. What type is 'PartNumber' I wonder if something weird is happening because VB is weakly typed
John P. Greiner
That's the prob, Mario. I got rid of the DataBinding on the TextBox and it works. I tried every way I could think of to get it to work while bound to the DataSource. I wanted to use a BindingNavigator and keep the TextBox bound but I guess I might as well forget it.
Here's the code that I'm currently using to scan the PartNumbers and get the Description:
Dim
rowCount As Integer = Me.PartsDataSet.Part_Numbers.Rows.Count Dim match As Boolean = False Dim thResult As String = "" Dim mainPartNum as String = txtMainPartNum.Text.ToString Dim jonat As Integer = 0 'jonat = Part_Numbers Row For jonat = 0 To rowCount - 1 If mainPartNum <> "" Then If mainPartNum = Me.PartsDataSet.Part_Numbers(jonat).PartNumber Thenmatch =
TruethResult = Me.PartsDataSet.Part_Numbers(jonat).Description
Exit For
End If Else
MessageBox.Show("Please enter a part number", "Hi", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Next
If (match = False) Then
MessageBox.Show("This part number is not in the database" & " " & mainPartNum, "Hi", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Thanks for helping you guys. I appreciate it. Now off to figger out how to ad a new row with PartNumber and/or Description.
rdx
The code looks close but you are not specifically typing mainpartNum and not selecting a specific property from the Me.PartsDataSet.Part_Numbers(i).PartNumber which will be an object for that particular item in the dataset
Try modifying the code to the following bolded items and see if that helps.
I would put a breakpoint on the IF statement line and look at the values and types of mainpartnum and Me.PartsDataSet.Part_Numbers(i).PartNumber.tostring and ensure that they are both of string type and that you do indeed have a match at some point.
Dim match As Boolean = False
Dim rowCount As Integer = Me.PartsDataSet.Part_Numbers.Rows.Count
Dim mainPartNum as String = txtMainPartNum.Text
For i = 0 To rowCount - 1
If mainPartNum = Me.PartsDataSet.Part_Numbers(i).PartNumber.tostring Then
match = True
Exit For
End If
Next
DotNet_Lover
Mufaddal
Thanks guys,
I did try it with .ToString, makes no difference.
Me.PartsDataSet.Part_Numbers(i).PartNumber gets the value of the PartNumer Column.
I get the value of the PartNumber from the DataSet but when I compare it to the value of the TextBox, it's like the PartNumber value is replaced by the TextBox value.
I haven't seen this before, very strange.
Any ideas
Thanks