checking variable for no value

This is a discussion on checking variable for no value within the C++ Programming forums, part of the General Programming Boards category; Heres the deal, its a windows program btu it more involves a C++ problem. Basically, the user has a dialog ...

  1. #1
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343

    checking variable for no value

    Heres the deal, its a windows program btu it more involves a C++ problem.

    Basically, the user has a dialog box open and they can input numbers and text, however, i want to make it so they HAVE to input something before clicking "ok" in order for it to process. Now, im a big OOP programmer in the past so i thought this method would work, any other method i try gets general errors.

    Code:
    case IDOK:
    GetDlgItemText(hwnd, G_COLOR, szGlowColor, 7);
    GetDlgItemText(hwnd, G_STRENGTH, szGlowStrength, 3);
    GetDlgItemText(hwnd, G_TEXT, szGlowString, 700);
    if(!szGlowColor) {
     MessageBox(hwnd, "You must enter in a value for the color", "Error", MB_OK);
     return FALSE;
    } else {
     if(!szGlowStrength) {
      MessageBox(hwnd, "You must enter in a value for the strength", "Error", MB_OK);
      return FALSE;
     } else {
       SendMessage(hEdit, EM_REPLACESEL, (WPARAM) 0, (LPARAM) "<table style='Filter: Glow(Color=#");
       SendMessage(hEdit, EM_REPLACESEL, (WPARAM) 0, (LPARAM) szGlowColor);
       SendMessage(hEdit, EM_REPLACESEL, (WPARAM) 0, (LPARAM) ", Strength=");
       SendMessage(hEdit, EM_REPLACESEL, (WPARAM) 0, (LPARAM) szGlowStrength);
       SendMessage(hEdit, EM_REPLACESEL, (WPARAM) 0, (LPARAM) ")'><tr><td>");
       SendMessage(hEdit, EM_REPLACESEL, (WPARAM) 0, (LPARAM) szGlowString);
       SendMessage(hEdit, EM_REPLACESEL, (WPARAM) 0, (LPARAM) "</td></table>");
       EndDialog(hwnd, 0);
       return TRUE;
      }
    }
    return FALSE;
    break;
    i need to check if szGlowColor and szGlowStrength have a value entered in them, doesn't matter if its numerical or alphabetical, just need to check is somethings in there.

    (EDIT: took out the formatting for horizontal scrolling sakes)
    Last edited by DarkViper; 01-08-2004 at 10:07 PM.
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    60

    Checking for NULL

    Hi, can you use the old strlen() function? Or, since you're doing it in C++, turn the results into temp string objects (STL) and ask them if they are null?

    (sorry if it's a dumb answer, but I'm fairly new to C++!)

    Nick.
    "It compiled, let's ship it!"

    Guitar Australia
    my site for some easy tutorials.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I believe GetDlgItemText returns the number of bytes copied:
    Code:
    //this could work:
    if (GetDlgItemText(/*...*/)==0)
     //Cannot continue
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660

    Re: Checking for NULL

    Originally posted by NickESP
    sorry if it's a dumb answer...
    I'm impressed that you deciphered a question

    gg

  5. #5
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    Originally posted by JaWiB
    I believe GetDlgItemText returns the number of bytes copied:
    Code:
    //this could work:
    if (GetDlgItemText(/*...*/)==0)
     //Cannot continue
    Thanks JaWiB, that did the trick, it now checks if something is entered, awsome.

    Again, thanks guys.
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  2. variable being reset
    By FoodDude in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2005, 12:30 PM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  4. Problem with a char variable set as a letter
    By 7smurfs in forum C++ Programming
    Replies: 6
    Last Post: 12-10-2004, 12:25 PM
  5. Static global variable acting as global variable?
    By Visu in forum C Programming
    Replies: 2
    Last Post: 07-20-2004, 08:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21