Results 1 to 12 of 12

Thread: A question of more efficient coding.

Hybrid View

  1. #1
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: A question of more efficient coding.

    If you are going use If statements to compare a variable/control value against multiple values, it is simpler to use a Select Case. One way would be like this:
    Code:
    Select Case MaskedTextBox1.Text
    Case "H"
       MsgBox "MaskedTextBox1.Text equals 'H'"
    Case "Li"
       MsgBox "MaskedTextBox1.Text equals 'Li'"
    ...
    End Select
    However, as it is this wont save much typing... thankfully you can use more than one value per case (simply separate them using commas), so you can do this:
    Code:
    Select Case MaskedTextBox1.Text
    Case "H", "Li", "Na", "K", "Rb", "Cs", ...
       TextBox1.Text = print(0)
    End Select
    It would also be possible to loop the elements arrays, but as your data doesn't contain the letters on their own it would be fairly "messy" code, and so it may be better to avoid that.

  2. #2

    Thread Starter
    New Member Jaycoba's Avatar
    Join Date
    Nov 2017
    Location
    In the sands of time.
    Posts
    13

    Re: A question of more efficient coding.

    Quote Originally Posted by si_the_geek View Post
    It would also be possible to loop the elements arrays, but as your data doesn't contain the letters on their own it would be fairly "messy" code, and so it may be better to avoid that.
    So if I separated the atomic# from the symbol using 2 arrays, I can loop the arrays of symbols. Is it possible to refer the array containing symbols to the array containing the atomic numbers and have them print out accordingly? "H" with "1.01" and so on? I'm assuming they would have to be on separate lines, but I've been wrong many times before.

Tags for this Thread

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