Results 1 to 1 of 1

Thread: [02/03] Using a variable for an array name HELP

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    8

    [02/03] Using a variable for an array name HELP

    Ok I'm trying to eliminate an entire case statement with 1 simple If statement but it won't let me use the variable "Manufacturer" for my array name. Any help? I want to find some way to use a variable to call a pre defined array without a case statement.

    VB Code:
    1. Private Sub frmPrinterProgram_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         'Assign values to the arrays
    3.         'Hewlett-Packard
    4.         HP(0) = "HP Officejet Pro K850"
    5.         HP(1) = "HP Officejet Pro K550"
    6.         HP(2) = "HP Deskjet 6840dt"
    7.         HP(3) = "HP Deskjet 6980dt"
    8.         HP(4) = "Hp Color LaserJet 2600n"
    9.         'Cannon
    10.         Canon(0) = "Pixima IP1500"
    11.         Canon(1) = "Pixima IP1600"
    12.         Canon(2) = "Pixima IP3000"
    13.         Canon(3) = "Pixima Pro9000"
    14.         Canon(4) = "Pixima Pro9500"
    15.         'Xerox
    16.         Xerox(0) = "Phaser 6120"
    17.         Xerox(1) = "Phaser 6300/6350"
    18.         Xerox(2) = "Phaser 7400"
    19.         Xerox(3) = "Phaser 7750"
    20.         Xerox(4) = "Phaser 8500/8550"
    21.         'Lexmark
    22.         Lexmark(0) = "Lexmark X1270"
    23.         Lexmark(1) = "Lexmark X2350"
    24.         Lexmark(2) = "Lexmark Z611"
    25.         Lexmark(3) = "Lexmark Z735"
    26.         Lexmark(4) = "Lexmark P4350"
    27.     End Sub
    28.  
    29. 'Change cboModel's Items list according to manufacturer
    30.     Private Sub cboManufacturer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboManufacturer.SelectedIndexChanged
    31.         Dim Manufacturer As String = cboManufacturer.Text
    32.         Dim Index As Integer
    33.         cboModel.Items.Clear()
    34.         'Problem code is the If statement below. The If and Case statement won't simultaneously exist but they're here for the comparison.
    35.         If Manufacturer = "HP" Or Manufacturer = "Canon" Or Manufacturer = "Xerox" Or Manufacturer = "Lexmark" Then
    36.             Do While Index < 5
    37.                 cboModel.Items.Add(Manufacturer(Index))
    38.                 Index = Index + 1
    39.             Loop
    40.         End If
    41.         Select Case Manufacturer
    42.             Case "HP"
    43.                 Index = 0
    44.                 Do While Index < 5
    45.                     cboModel.Items.Add(HP(Index))
    46.                     Index = Index + 1
    47.                 Loop
    48.             Case "Canon"
    49.                 Do While Index < 5
    50.                     cboModel.Items.Add(Canon(Index))
    51.                     Index = Index + 1
    52.                 Loop
    53.             Case "Xerox"
    54.                 Do While Index < 5
    55.                     cboModel.Items.Add(Xerox(Index))
    56.                     Index = Index + 1
    57.                 Loop
    58.             Case "Lexmark"
    59.                 Do While Index < 5
    60.                     cboModel.Items.Add(Lexmark(Index))
    61.                     Index = Index + 1
    62.                 Loop
    63.         End Select
    64.         cboModel.Text = "Select a model"
    65.     End Sub

    I want to get rid of the above case statement and replace it with that If statement, if it's possible.
    Last edited by anarchyPenguin; Apr 27th, 2006 at 11:27 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width