Announcement

Collapse
No announcement yet.

InputBox$ and the cancel button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Kurt Kuzba
    replied
    Originally posted by James C Morgan View Post
    I need some help to create a dialog like window so I can add 2 textboxes
    to find a file name and then search within that file
    I would like to have a second dialog popup called from the first dialog or inputbox$
    i could not find a place to start a new topic
    thanks
    James Morgan
    New topic HERE
    This example code provides a custom popup input box. #COMPILE EXE #DIM ALL #INCLUDE "Win32API.inc" %IDC_DoBtn = 500 %IDC_TxtLbl = 501 FUNCTION PBMAIN() AS LONG LOCAL hDlg AS LONG DIALOG NEW PIXELS, 0, "Custom InputBox", 300, 300, 320, 60, %WS_SYSMENU TO hDlg CONTROL ADD BUTTON, hDlg,

    Leave a comment:


  • Jim Fritts
    replied
    Egbert's updated link to Safe wrapper for INPUTBOX$ in Source Code.

    Leave a comment:


  • Dale Yarker
    replied
    Each section has a "+ New Topic" button.

    In the Samples\DDT\FileFind directory where PB is installed is code to search for a file. That can be modified for the second dialog.

    (copy the files before changing, the samples will stay original)

    Cheers,

    Leave a comment:


  • James C Morgan
    replied
    I need some help to create a dialog like window so I can add 2 textboxes
    to find a file name and then search within that file
    I would like to have a second dialog popup called from the first dialog or inputbox$
    i could not find a place to start a new topic
    thanks
    James Morgan

    Leave a comment:


  • Michael Mattias
    replied
    I think it's equal.

    VERIFY giveth position of offending character and does not require explicit MID$/ASC code; VERIFY taketh away what seems more natural to me:
    Code:
      IF ISTRUE VERIFY (myString, "0123456789") THEN 
          MSGBOX "All characters of mystring are numeric digits"
      .....
    Semantic, I know, but it is what "feels" correct to me.

    MCM

    Leave a comment:


  • Egbert Zijlema
    replied
    Originally posted by Michael Mattias View Post
    >validates a "numbers only" setting
    (...)
    The PB VERIFY function is kind of funky... it returns FALSE (zero) on a "good" verification. Probably why it's often overlooked for this kind of editing.
    (...)
    The "plus offset" is, you get the position of the first offending character.
    (...)
    Well, PB's VERIFY function is not the only one. Quite a lot of Windows API functions return %ERROR_SUCCESS (= 0) if ending successful. What you call the "plus offset" is completely irrelevant in this routine. When one of the characters is invalid (don't mind which one), my routine simply re-runs to give the user a new chance.

    So, I do not exactly understand your message. Did you just want to point me to an equal-worthy alternative or to a "far better solution"?

    Leave a comment:


  • Michael Mattias
    replied
    >validates a "numbers only" setting
    Code:
      IF ISTRUE(iNumerals) THEN                           ' flag "digits only" is set
        FOR iPos = 1 TO LEN(sResult)
          SELECT CASE AS LONG ASC(sResult, iPos)
            CASE < 48, > 57
    ...
    ===>
    Code:
    IF Istrue (iNumerals) THEN
        IF ISTRUE VERIFY(sResult, "0123456789") THEN 
    ...

    The PB VERIFY function is kind of funky... it returns FALSE (zero) on a "good" verification. Probably why it's often overlooked for this kind of editing.

    The "plus offset" is, you get the position of the first offending character.

    Or, in COBOL....
    Code:
      IF sResult IS NOT NUMERIC THEN 
     ...

    Leave a comment:


  • Egbert Zijlema
    replied
    Safe wrapper in SC forum now

    Given some incertainties throughout this thread, especially in respect with the cancel button, I've tried to create a "safe" wrapper for Power Basic's INPUTBOX$ function. Although it is a string function, my wrapper function also validates a "numbers only" setting.

    You'll find it here: http://www.powerbasic.com/support/pb...221#post306221

    Leave a comment:


  • Dave Biggs
    replied
    LATER: Sorry, didn't read the help file very well. It is documented. See: ASC in Keyword Reference.
    The apology should be made by me - I didn't make it clear I was quoting the help file - nor which part.

    Leave a comment:


  • Egbert Zijlema
    replied
    Originally posted by Dave Biggs View Post
    "If the string passed is null (zero-length) or the position is zero or greater than the length of the string, the value -1 is returned".
    Position? Position of what?

    Apart from that, a zero-length string obviously returns ascii -1. That's exactly what I said in my previous message. What I want to know is whether it's a documented feature or not.

    LATER: Sorry, didn't read the help file very well. It is documented. See: ASC in Keyword Reference.
    Last edited by Egbert Zijlema; 7 Jan 2009, 03:38 AM. Reason: RTFM

    Leave a comment:


  • Dave Biggs
    replied
    Code:
      sResult = ""
      MsgBox "Ascii code: " & FORMAT$(ASC(sResult)), 64, "Test Ascii code"
    "If the string passed is null (zero-length) or the position is zero or greater than the length of the string, the value -1 is returned".

    Leave a comment:


  • Egbert Zijlema
    replied
    Empty string with ascii code -1?

    Originally posted by Fred Harris View Post
    It seems the InputBox$ function returns an empty string
    when the Cancel button is clicked, even if a default string
    is in the entry field. (...)
    That's what I've always thought. But... if you query for the string's ascii code, -1 is returned. Can somebody explain this? I like to know if this is a safe method to verify if the user pressed the cancel button.

    Code:
    '  run this code and press the Cancel button to see that an empty string
    '  returns an ascii value of minus one
    
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
      LOCAL sResult AS STRING
    
      sResult = INPUTBOX$("First Name", "Test Inputbox$", "Egbert")
      MSGBOX "String content: " & sResult & $CRLF & _
             "String length: " & FORMAT$(LEN(sResult)) & $CRLF & _
             "Ascii code: " & FORMAT$(ASC(sResult)), 64, "Test Inputbox$"
    END FUNCTION

    Leave a comment:


  • Michael Mattias
    replied
    if cancel or the x to close, causes the returned string to be nothing.
    That sure doesn't sound like the 'correct' behavior if one supplies a 'default' value.

    Maybe that should be called an "initial" value instead of a "default" value.

    Regardless, this behavior should documented.

    Leave a comment:


  • Cliff Nichols
    replied
    You are right. Dummy me staring at the same block of code so long that until
    I came home and took a break, it was then obvious that if cancel or
    the x to close, causes the returned string to be nothing.

    My other problem was a check to verify that the value of the string would not be
    zero (and obviously the value of nothing is zero)

    Thanks to all

    ------------------

    Leave a comment:


  • Fred Harris
    replied
    It seems the InputBox$ function returns an empty string
    when the Cancel button is clicked, even if a default string
    is in the entry field. That makes sense kind of. Just tried
    it with my code above.

    ------------------
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

    Leave a comment:


  • Michael Mattias
    replied
    If you need to know if he canceled rather than simply 'did not changed the default,' perhaps INPUTBOX$ is not the optimal choice of functions here.
    Code:
          Prompt  [editable default]
        
              <OK>   <Cancel>
    I think that's about a ten-minute DDT dialog job....

    Leave a comment:


  • Fred Harris
    replied
    Just tried this and it seems to work

    Code:
    #Compile Exe
    #Dim All
    
    Function PBMain() As Long
      Local strText As String, strResult As String
      
      strText="December"
      strResult=InputBox$("Enter A Month",,strText)
      If Len(strResult) Then
         MsgBox("User Entered " & strResult)
      Else
         MsgBox("User Cancelled!")
      End If
      
      PBMain=0
    End Function
    ------------------
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

    Leave a comment:


  • Fred Harris
    replied
    Cliff,

    Couldn't you just compare the default string before and
    after? If it isn't the same, then the user changed something.
    If it is the same, perhaps he hit cancel. Havn't tried it,
    that's just my guess.

    ------------------
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

    Leave a comment:


  • Cliff Nichols
    started a topic InputBox$ and the cancel button

    InputBox$ and the cancel button

    This should be simple but I can find no information via search or in POFFS

    If I use an inputbox$, how do I know if the user pressed the cancel button?
    (Checking the length of the string is no good because I set a default value)

    Do I have to make my own custom input dialog so that I can check which button was pressed?

    should be a simple answer, but I am guessing I will have to go custom?

    ------------------
Working...
X