buttons in a form

Discussion in 'Cadence' started by bsrin, Mar 17, 2010.

  1. bsrin

    bsrin Guest

    Hi All,
    I have 100 buttons in my form with buttontext "1", "2",
    "3" ..... so on . I need to print number with respect to selected
    button. For example if a button is pressed which have button text
    "50" , I need to print "50" as output.
    Thanks in Advance.
    bsrin
     
    bsrin, Mar 17, 2010
    #1
  2. bsrin wrote, on 03/17/10 10:34:
    When you build the form, create the callback string so that it has the number as
    part of the callback (e.g. using sprintf).

    This is a wild guess because you gave very little info to go on - you didn't
    show any code, or give any clue how you're creating the form.

    Regards,

    Andrew.
     
    Andrew Beckett, Mar 17, 2010
    #2
  3. bsrin

    bsrin Guest

    Hi Andrew,
    Thanks for u reply, I didnot get u. I have a form which
    consists of a listbox field on left with few choices and callbacks,
    and scrollbar filed with 100 buttons on right. My code is like this

    /* I have created listbox field with function
    trnames = hiCreateListBoxField(?name
    'trnames.........) */

    /* for creating scrollbar region with 100 buttons */
    trnumm = nil
    for(i 1 100
    trnumm = constar(artMakeString(i) trnumm)
    )
    trnumm = reverse(trnumm)
    scroll_nums = hiCreateScrollRegion(?name 'scroll_nums)

    foreach(i numm
    trstri = stringToSymbol(strcat("trstr" i))
    rowbutt = evalstring(i)/10
    colbutt = modulo(evalstring(i) 10)
    hiAddField(scroll_nums list(
    hiCreateFormButton(?
    name stringToSymbol(get_pname(trstri))
    ?buttonText i
    ?callback
    "println(i)")
    list(colbutt*30
    rowbutt*30) list(30 30) 10
    )
    )
    )


    hiCreateAppForm(?name 'trAppForm
    ?fields list(list(trnames 0:0 200:500)
    list(scroll_nums 200:0 300:500))
    ?initialsize list(500 500)
    ?fieldfocus 'allTypein
    )

    hiDisplayForm(trAppform)


    I am getting the form with specified listbox on left and buttons in
    scroll region on right. My problem is when I click the button in
    scrollbar region , the output is the value of current "i" in CIW
    window . But I want the buttonText which i have pressed . The form
    should not close after a click on button, still it should wait for new
    button press until the form is closed by ok or cancel button.
    I need your help in these.

    Thanks.
     
    bsrin, Mar 17, 2010
    #3
  4. bsrin wrote, on 03/17/10 14:04:

    Hmm. First of all, saying things like "Thanks for 'u' reply, I didnot get 'u'"
    immediately gets my back up. There's no tax on characters, so please write
    English words (even if English is not your first language, using such
    abbreviations should be the preserve of SMS text messaging, not somewhere where
    you expect somebody to be able to easily read your questions).

    Secondly your code does not run as is, for several reasons:

    1. You have a line foreach(i numm ... but no variable numm (it should be trnumm).
    2. The formatting is awful, making it hard to read. Line wrapping after meant
    that ?name got split into ? and name on separate lines, which broke the code.
    3. The hiCreateAppForm refers to a variable trnames, not defined anywhere
    4. The arguments to hiCreateAppForm ?initialsize and ?fieldfocus should be
    ?initialSize and ?fieldFocus

    Luckily I had the patience to ignore your 'u' and to fix the mistakes in your
    code (best to test it before posting, so that those of us trying to help out in
    our spare time do not spend excessive amounts of that time fixing your mistakes,
    which limits the likelihood of you getting an answer).

    Change the ?callback argument in hiCreateFormButton to:

    ?callback sprintf(nil "println(%s)" i)

    As I said, build the callback. You cannot just reference a variable i in your
    callback as you did, because it will not be in scope at the time the callback is
    executed.

    Other suggestion - don't use evalstring() to convert a string to an integer. Use
    atoi(). evalstring() is less efficient, and if for some reason the string you're
    evaluating contains (say) "exit()" you'll realise why you shouldn't use evalstring!

    Andrew.
     
    Andrew Beckett, Mar 17, 2010
    #4
  5. bsrin

    bsrin Guest



    Hi Andrew,
    I deeply appologize for my previous mail. I have no skills
    especially to post questions and way of expressing things. Please
    forgive me for my typo mistakes like initialsize , fieldfocus instead
    of initialSize and fieldFocus .
    I have posted likely correct way but the appearance in forum is
    different. I don't know where I did mistake.
    Thanks for your reply once again. The reply is so important for me.
    Yes , its "trnumm" not "numm".

    ?callback sprintf(nil "println(%s)" i)

    Hurry! its working . I am very happy. Its fantastic.
     
    bsrin, Mar 18, 2010
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.