473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How do i get my program to select the proper delivery based on what the user inputs?

Public Class frmMain

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' fills the list box with values

lstDelivery.Items.Add("Mail - Standard")
lstDelivery.Items.Add("Mail - Priority")
lstDelivery.Items.Add("FedEx - Standard")
lstDelivery.Items.Add("FedEx - Overnight")
lstDelivery.Items.Add("UPS")


End Sub

Private Sub txtPartNum_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPartNum.Enter
txtPartNum.SelectAll()
End Sub

Private Sub txtPartNum_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPartNum.TextChanged
' clears the list box selection

lstDelivery.SelectedIndex = -1
End Sub

Private Sub btnDelivery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelivery.Click

Dim strtxtPartNum As String
Dim Index As Integer
Dim lstDelivery() As String = {"MP", "MS", "FS", "FO", "U"}

strtxtPartNum = txtPartNum.Text.ToUpper.ToString

If strtxtPartNum Like "##[A-Z][A-Z]" Then
lstDelivery.SelectedIndex = 1

ElseIf strtxtPartNum Like "##[A-Z]" Then

Else
MessageBox.Show("Invalid part number", _
"Part number", MessageBoxButtons.OK, _
MessageBoxIcon.Information)


End If

End Sub


End Class
Feb 7 '10 #1

✓ answered by yarbrough40

which object type do you have for the user to type? if it is a text box then use this method - I'm assuming your textbox is called "txtPartNum"...... don't use the item list you are using ( {"MP", "MS", "FS", "FO", "U"}) <-- ignore this - instead call the value of the textbox directly and evaluate based on that value

Expand|Select|Wrap|Line Numbers
  1. If txtPartNum.SelectedItem.Text Like "##MP" Then
  2. lstDelivery.SelectedIndex = 0
  3. ElseIf txtPartNum.SelectedItem.Text Like "##MS" Then
  4. lstDelivery.SelectedIndex = 1
  5. ElseIf txtPartNum.SelectedItem.Text Like "##FS" Then
  6. lstDelivery.SelectedIndex = 2
  7. ElseIf txtPartNum.SelectedItem.Text Like "##FO" Then
  8. lstDelivery.SelectedIndex = 3
  9. ElseIf txtPartNum.SelectedItem.Text Like "##U" Then
  10. lstDelivery.SelectedIndex = 4
  11. Else
  12. MessageBox.Show("Invalid part number", _
  13. "Part number", MessageBoxButtons.OK, _
  14. MessageBoxIcon.Information) 
  15.  
  16. End If
  17.  

21 1573
yarbrough40
320 100+
please retype your question and be a bit clearer. I'm not understanding what you are trying to do based on this code.

unless I'm missing something,
based on the title of your post alone I would assume that you would have three subs that do something like sub Fedex(), sub UPS(), sub USPS() etc. then you would call those subs like so:
Expand|Select|Wrap|Line Numbers
  1. if DropDownList1.selecteditem.Text = "FedEx" then
  2. FedEx()
  3. ElseIf DropDownList1.selecteditem.Text = "UPS" then
  4. UPS()
  5. ElseIf DropDownList1.selecteditem.Text = "USPS" then
  6. USPS()
  7. End If
  8.  
  9.  
Feb 7 '10 #2
this should allow the user to enter a part number like ("##[A-Z][A-Z]) or like "##[A-Z]" meaning the user can input 73mp or 45U and it should select(highlight) the appropriate code in the list box, else desplay the message Invalid part number. The like operator has to be used in this code.
Feb 7 '10 #3
yarbrough40
320 100+
why are you using a 'like' operator if you are enabling the application to say they have an invalid part number?
I think the best way to do what you want is to create a table in a database - store all of your valid part numbers in one column and the corresponding index number for the delivery method listbox in another column like so:
PartNum---------IndexNum

73mp-----------------2
45U-------------------1
33X-------------------1
22Y-------------------3

then just open a connection to your table and retrieve the index based upon what the user inputs.

Select IndexNum from PartsTable where PartNum = '" & txtPartNum.Text & "' "
Feb 7 '10 #4
My question should have been:
How do i get my program to select the proper delivery CODE based on a code that the user inputs.
Feb 7 '10 #5
Thats to deep yarbrough, i just need to use the like operator to compare the user code input (ie 33mp or 65FO) to string with the list box which has:

lstDelivery.Items.Add("Mail - Standard")
lstDelivery.Items.Add("Mail - Priority")
lstDelivery.Items.Add("FedEx - Standard")
lstDelivery.Items.Add("FedEx - Overnight")
lstDelivery.Items.Add("UPS")

Example if the user inouts any two number followed by MS it should select /highlight the ("Mail - Standard").. If the user inputs any two numbers followed by a U it should select/highlight)("UPS")

The string code is {"MP", "MS", "FS", "FO", "U"}
MP= lstDelivery.Items.Add("Mail - Standard")
MS=lstDelivery.Items.Add("Mail - Priority")
FS=lstDelivery.Items.Add("FedEx - Standard")
FO=lstDelivery.Items.Add("FedEx - Overnight")
U=lstDelivery.Items.Add("UPS")
Feb 7 '10 #6
Thats the way the teacher wants it...it has to be used in conjunction with the string i guess!
Feb 7 '10 #7
If you have VB on your pc I can send you the file so that you can run it and see what I need to do......
Feb 7 '10 #8
yarbrough40
320 100+
ok then how about this
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim DeliveryMeth as String = Substring(txtPartNum.Text(2,2))
  3.  
  4. if DeliveryMeth = "MP" then 
  5. lstDelivery.SelectedIndex = 1
  6. ElseIf DeliveryMeth = "MS" then 
  7. lstDelivery.SelectedIndex = 2
  8. ElseIf DeliveryMeth = "FS" then 
  9. lstDelivery.SelectedIndex = 3
  10. ElseIf DeliveryMeth = "FO" then 
  11. lstDelivery.SelectedIndex = 4
  12. ElseIf DeliveryMeth = "U" then 
  13. lstDelivery.SelectedIndex = 5
  14. Else
  15. MessageBox.Show("Invalid part number", _
  16. "Part number", MessageBoxButtons.OK, _
  17. MessageBoxIcon.Information)
  18.  
  19. End If
  20.  
Feb 7 '10 #9
that might work, can i replace the = with LIKE
Feb 7 '10 #10
yarbrough40
320 100+
do you HAVE to use the like operator? is that part of an assignment or something?
Feb 7 '10 #11
yes it is part of my assignment......I have been working on it for over 3days!
Feb 7 '10 #12
yarbrough40
320 100+
ok well with my example, there is no need to use 'like' but I suppose it would work
Feb 7 '10 #13
now it just shows the message box when i use this code:

Dim strtxtPartNum As String
Dim txtPartNum() As String = {"MP", "MS", "FS", "FO", "U"}

strtxtPartNum = txtPartNum.ToString()

If strtxtPartNum Like "##MP" Then
lstDelivery.SelectedIndex = 0
ElseIf strtxtPartNum Like "##MS" Then
lstDelivery.SelectedIndex = 1
ElseIf strtxtPartNum Like "##FS" Then
lstDelivery.SelectedIndex = 2
ElseIf strtxtPartNum Like "##FO" Then
lstDelivery.SelectedIndex = 3
ElseIf strtxtPartNum Like "##U" Then
lstDelivery.SelectedIndex = 4
Else
MessageBox.Show("Invalid part number", _
"Part number", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Feb 7 '10 #14
I know im a newbie but what am I doing wrong???????????????
Feb 7 '10 #15
yarbrough40
320 100+
which object type do you have for the user to type? if it is a text box then use this method - I'm assuming your textbox is called "txtPartNum"...... don't use the item list you are using ( {"MP", "MS", "FS", "FO", "U"}) <-- ignore this - instead call the value of the textbox directly and evaluate based on that value

Expand|Select|Wrap|Line Numbers
  1. If txtPartNum.SelectedItem.Text Like "##MP" Then
  2. lstDelivery.SelectedIndex = 0
  3. ElseIf txtPartNum.SelectedItem.Text Like "##MS" Then
  4. lstDelivery.SelectedIndex = 1
  5. ElseIf txtPartNum.SelectedItem.Text Like "##FS" Then
  6. lstDelivery.SelectedIndex = 2
  7. ElseIf txtPartNum.SelectedItem.Text Like "##FO" Then
  8. lstDelivery.SelectedIndex = 3
  9. ElseIf txtPartNum.SelectedItem.Text Like "##U" Then
  10. lstDelivery.SelectedIndex = 4
  11. Else
  12. MessageBox.Show("Invalid part number", _
  13. "Part number", MessageBoxButtons.OK, _
  14. MessageBoxIcon.Information) 
  15.  
  16. End If
  17.  
Feb 8 '10 #16
You assumed right! Im about to try ur solution right now!!!!!!!!!!!!!!
Feb 8 '10 #17
It underlines the txtPartNum.SelectedItem and show that SelectedItem is not a member of 'System.Windows.Forms.Textbox...After I Dim txtPartNum AS String it show that SelectedItem is not a member of String!
Feb 8 '10 #18
yarbrough40
320 100+
txtPartNum.Text sorry
Feb 8 '10 #19
Wow, I am deeply indebted to you........It Works Yahoooooooooo. So now do I just click on choose the best answer?

thanks a Million$$$$$$$$$$$$$$$$$$$
Feb 8 '10 #20
yarbrough40
320 100+
your welcome.... as far as selecting best answer goes I'm not sure how that works - you're on your own there : )
Feb 8 '10 #21
Ok once again Thx, I will be looking for your ID if I have any more problems!!!!!!!!!!!!!!
Feb 8 '10 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Steve Lefevre | last post by:
Hey folks -- I have a series of selectboxes on a web form. I would like to have a javascript jump the focus to the next selectbox when the user presses a key. Each box has the values 1 through...
6
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
1
by: evilasukakitty | last post by:
I too am new to the whole C++ language, and I am an eager beaver and wish I could absorb it all instantly, but I can't. The first program I wrote (very simple) was easy enough, using your basic cin...
6
by: Vortexmind | last post by:
Hi all I was wondering if this is possible in Javascript. I want to make a bookmarklet. When a user launches it, it tells the user to select an element in the page (for example a textarea) with...
7
by: Danielle | last post by:
All - I was asked to work on a project converting some weather data. The program used to convert the data is written in Quick Basic. I am only a novice programmer and while I can see from the...
4
by: vadrama | last post by:
takes a list of grades and counts the amount A's, B's, C's etc... I am using a while statement to count the total number of grades which works great, but my if and else statements to count how...
14
namcintosh
by: namcintosh | last post by:
Hello, everyone. Well, let me cut to the chase and explain my problem. I am trying to devise a menu plan that uses the if/else if and the while loop. The program calculates the user's weight...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.