< Return to Video

Visual Basic Empty String vs. Blank Space

  • 0:00 - 0:03
    The problem with your 'Cancel' button not
  • 0:03 - 0:07
    working with your input box, I suspect is
  • 0:07 - 0:10
    from this line here where you're assigning
  • 0:10 - 0:15
    a blank space to the strCancelClicked variable
  • 0:15 - 0:19
    You're assigning a blank space. What's
  • 0:19 - 0:21
    actually in the input box when you click
  • 0:21 - 0:25
    the 'Cancel' button is 'no character' or
  • 0:25 - 0:28
    what is what we call an empty string.
  • 0:28 - 0:30
    Now I've actually tested this and I want to
  • 0:30 - 0:32
    test it and show you how I tested it.
  • 0:32 - 0:37
    I test by setting a break point at
    the 'Do Until' loop.
  • 0:37 - 0:41
    I'm going to run or debug your program
  • 0:41 - 0:44
    when the program code gets to this line
  • 0:44 - 0:47
    it will pause, we can actually look at
  • 0:47 - 0:50
    the values in each of these variables and
  • 0:50 - 0:54
    so what I'll do is run your program, I'll
  • 0:54 - 0:57
    enter two values for temperatures and then
  • 0:57 - 1:00
    for the third input I'll click the 'Cancel'
  • 1:00 - 1:04
    button. But after each value I input the
  • 1:04 - 1:07
    program is going to pause at this line
  • 1:07 - 1:10
    and allows us to look at the variables and
  • 1:10 - 1:12
    then we can continue on until the next
  • 1:12 - 1:13
    input and so on.
  • 1:13 - 1:21
    I'll start debugging. Enter the
    temperature for month number 1.
  • 1:21 - 1:24
    Click the 'OK' button. The program code
  • 1:24 - 1:27
    pauses here. I can see the number of
  • 1:27 - 1:30
    entries is one. Of course the max entries
  • 1:30 - 1:36
    should be 12. The strTemp is 98, that's
  • 1:36 - 1:40
    what I entered and the strCanceled is
  • 1:40 - 1:45
    you can faintly see it there
    'quote' 'space' 'quote'.
  • 1:45 - 1:48
    Again that's exactly what you assigned it.
  • 1:48 - 1:54
    Now I can continue the program code by
  • 1:54 - 1:56
    clicking the F5 or if we wanted to we
  • 1:56 - 2:00
    could go line by line by clicking the F8 key.
  • 2:00 - 2:03
    But we are just going to continue.
  • 2:03 - 2:05
    The program is going to prompt me for
  • 2:05 - 2:12
    month #2. Again we pause, the number of
  • 2:12 - 2:15
    entries is now 2, max number of entries
  • 2:15 - 2:18
    should stay at 12. What I entered into
  • 2:18 - 2:21
    the input box is 99 and again the
  • 2:21 - 2:26
    strCanceledClick is the 'space'.
  • 2:26 - 2:30
    One more continue. For the third
  • 2:30 - 2:32
    temperature I'm going to click the
  • 2:32 - 2:36
    'Cancel' button. Now the program again
  • 2:36 - 2:42
    pauses here, third entry, notice this
  • 2:42 - 2:47
    strTemp is 'quote' 'quote' but
  • 2:47 - 2:52
    strCanceled is 'quote' 'space' 'quote'.
  • 2:52 - 2:55
    That's why when we continue our program
  • 2:55 - 2:58
    you are prompted to enter a number of
  • 2:58 - 3:02
    months instead of it canceling. So what
  • 3:02 - 3:04
    I'm going to do is actually stop the
  • 3:04 - 3:09
    program, say 'Yes' you're not cancelling
  • 3:09 - 3:12
    out because of the blank space here. You
  • 3:12 - 3:15
    get rid of the blank space, I'm also going
  • 3:15 - 3:18
    to remove the break point. We're going
  • 3:18 - 3:22
    to run the program again. Now strCenceled
  • 3:22 - 3:27
    will equal the empty string. Again I'll
  • 3:27 - 3:31
    enter two temperatures, notice there's no
  • 3:31 - 3:35
    break point so it's not pausing the code.
  • 3:35 - 3:39
    For the third temperature I click 'Cancel'
  • 3:39 - 3:41
    and it breaks out of the loop, averages
  • 3:41 - 3:43
    the two temperatures, displays it,
  • 3:43 - 3:45
    the program is working fine.
  • 3:45 - 3:47
    I hope that you understand now the
  • 3:47 - 3:51
    difference between an empty string
    and a blank space.
Title:
Visual Basic Empty String vs. Blank Space
Description:

more » « less
Video Language:
English
Duration:
03:51

English subtitles

Revisions