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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blknmld69
    New Member
    • Feb 2010
    • 69

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

    Public Class frmMain

    Private Sub btnExit_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles btnExit.Click
    Me.Close()
    End Sub

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

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


    End Sub

    Private Sub txtPartNum_Ente r(ByVal sender As Object, ByVal e As System.EventArg s) Handles txtPartNum.Ente r
    txtPartNum.Sele ctAll()
    End Sub

    Private Sub txtPartNum_Text Changed(ByVal sender As Object, ByVal e As System.EventArg s) Handles txtPartNum.Text Changed
    ' clears the list box selection

    lstDelivery.Sel ectedIndex = -1
    End Sub

    Private Sub btnDelivery_Cli ck(ByVal sender As Object, ByVal e As System.EventArg s) Handles btnDelivery.Cli ck

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

    strtxtPartNum = txtPartNum.Text .ToUpper.ToStri ng

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

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

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


    End If

    End Sub


    End Class
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2
    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:
    Code:
    if DropDownList1.selecteditem.Text = "FedEx" then
    FedEx()
    ElseIf DropDownList1.selecteditem.Text = "UPS" then
    UPS()
    ElseIf DropDownList1.selecteditem.Text = "USPS" then
    USPS()
    End If

    Comment

    • blknmld69
      New Member
      • Feb 2010
      • 69

      #3
      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(highligh t) the appropriate code in the list box, else desplay the message Invalid part number. The like operator has to be used in this code.

      Comment

      • yarbrough40
        Contributor
        • Jun 2009
        • 320

        #4
        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 & "' "

        Comment

        • blknmld69
          New Member
          • Feb 2010
          • 69

          #5
          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.

          Comment

          • blknmld69
            New Member
            • Feb 2010
            • 69

            #6
            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.Ite ms.Add("Mail - Standard")
            lstDelivery.Ite ms.Add("Mail - Priority")
            lstDelivery.Ite ms.Add("FedEx - Standard")
            lstDelivery.Ite ms.Add("FedEx - Overnight")
            lstDelivery.Ite ms.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.Ite ms.Add("Mail - Standard")
            MS=lstDelivery. Items.Add("Mail - Priority")
            FS=lstDelivery. Items.Add("FedE x - Standard")
            FO=lstDelivery. Items.Add("FedE x - Overnight")
            U=lstDelivery.I tems.Add("UPS")

            Comment

            • blknmld69
              New Member
              • Feb 2010
              • 69

              #7
              Thats the way the teacher wants it...it has to be used in conjunction with the string i guess!

              Comment

              • blknmld69
                New Member
                • Feb 2010
                • 69

                #8
                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......

                Comment

                • yarbrough40
                  Contributor
                  • Jun 2009
                  • 320

                  #9
                  ok then how about this
                  Code:
                   
                  Dim DeliveryMeth as String = Substring(txtPartNum.Text(2,2))
                  
                  if DeliveryMeth = "MP" then 
                  lstDelivery.SelectedIndex = 1
                  ElseIf DeliveryMeth = "MS" then 
                  lstDelivery.SelectedIndex = 2
                  ElseIf DeliveryMeth = "FS" then 
                  lstDelivery.SelectedIndex = 3
                  ElseIf DeliveryMeth = "FO" then 
                  lstDelivery.SelectedIndex = 4
                  ElseIf DeliveryMeth = "U" then 
                  lstDelivery.SelectedIndex = 5
                  Else
                  MessageBox.Show("Invalid part number", _
                  "Part number", MessageBoxButtons.OK, _
                  MessageBoxIcon.Information)
                  
                  End If

                  Comment

                  • blknmld69
                    New Member
                    • Feb 2010
                    • 69

                    #10
                    that might work, can i replace the = with LIKE

                    Comment

                    • yarbrough40
                      Contributor
                      • Jun 2009
                      • 320

                      #11
                      do you HAVE to use the like operator? is that part of an assignment or something?

                      Comment

                      • blknmld69
                        New Member
                        • Feb 2010
                        • 69

                        #12
                        yes it is part of my assignment..... .I have been working on it for over 3days!

                        Comment

                        • yarbrough40
                          Contributor
                          • Jun 2009
                          • 320

                          #13
                          ok well with my example, there is no need to use 'like' but I suppose it would work

                          Comment

                          • blknmld69
                            New Member
                            • Feb 2010
                            • 69

                            #14
                            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.ToSt ring()

                            If strtxtPartNum Like "##MP" Then
                            lstDelivery.Sel ectedIndex = 0
                            ElseIf strtxtPartNum Like "##MS" Then
                            lstDelivery.Sel ectedIndex = 1
                            ElseIf strtxtPartNum Like "##FS" Then
                            lstDelivery.Sel ectedIndex = 2
                            ElseIf strtxtPartNum Like "##FO" Then
                            lstDelivery.Sel ectedIndex = 3
                            ElseIf strtxtPartNum Like "##U" Then
                            lstDelivery.Sel ectedIndex = 4
                            Else
                            MessageBox.Show ("Invalid part number", _
                            "Part number", MessageBoxButto ns.OK, _
                            MessageBoxIcon. Information)

                            Comment

                            • blknmld69
                              New Member
                              • Feb 2010
                              • 69

                              #15
                              I know im a newbie but what am I doing wrong?????????? ?????

                              Comment

                              Working...