validation problem

janu123

Member
Joined
Mar 11, 2012
Messages
8
Programming Experience
Beginner
Hi...

well i am creating a sales analysis program...

The form is as follows
price changer.jpg

so..here the user is allowed a to select a product and enter a price . When the price is entered and Priche change button is clicked the price get stored in an array
which is later recalled for calculation purpose.
What i am suck is ....i want to validate the price ...so that when the user enters a invalid character to the price a error message pops up
I tried using tryparse ...the error messaged poped up ..but when the user entered a valid price it didnt get transfered to the array

My code is as follows



intMediaPrice () is the array

Private Sub btnPrice_Click(sender As System.Object, e As System.EventArgs) Handles btnPrice.Click
If cbMedia.Text = "8-Track" Then
intMediaPrice(0) = txtPrice.Text
frmSalesData.DisplayData()
ElseIf cbMedia.Text = "Cassette" Then
intMediaPrice(1) = txtPrice.Text
frmSalesData.DisplayData()
ElseIf cbMedia.Text = "CD" Then
intMediaPrice(2) = txtPrice.Text
frmSalesData.DisplayData()
ElseIf cbMedia.Text = "Bluray" Then
intMediaPrice(3) = txtPrice.Text
frmSalesData.DisplayData()
ElseIf cbMedia.Text = "Flash" Then
intMediaPrice(4) = txtPrice.Text
frmSalesData.DisplayData()
End If

End Sub

Function picBox()
PictureBox1.Visible = False
PictureBox2.Visible = False
PictureBox3.Visible = False
PictureBox4.Visible = False
PictureBox5.Visible = False
PictureBox6.Visible = False
End Function

Private Sub cbMedia_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbMedia.SelectedIndexChanged
If cbMedia.Text = "8-Track" Then
picBox()
PictureBox1.Visible = True
ElseIf cbMedia.Text = "Cassette" Then
picBox()
PictureBox2.Visible = True
ElseIf cbMedia.Text = "CD" Then
picBox()
PictureBox3.Visible = True
ElseIf cbMedia.Text = "Bluray" Then
picBox()
PictureBox4.Visible = True
ElseIf cbMedia.Text = "Flash" Then
picBox()
PictureBox5.Visible = True
End If
End Sub


End Class


any help is appreciated

thank you
 
TryParse is the way to go but I don't see where you're using it so I can't say what you did wrong. TryParse returns a Boolean to indicate whether the text was successfully parsed or not, so you generally use it as the condition for an If or If...Else statement. You can use the number inside the If statement because the conversion was successful and the Else block is where you would display and error message.
 
Back
Top