value not assigned error

Discussion in 'Questions (Windows Mobile)' started by Cableguy, May 24, 2007.

  1. Cableguy

    Cableguy Expert Licensed User

    Hi,

    I have a panel in wich i load up to 10 label with the filenames of a specific directory...so far so good.
    Then I use the mouse down event to determine the user choice, and change the correspondent label to a red font...so far so good....unless i tap on an empty label, then I get the error:

    If control(selected).text<>"" then control(selected).fontcolor=cred

    Error description:
    Variable selected was not assigned any value.


    If i disable the "check unassigned variables" option I get a NullReference error!!!

    I know it wasn't, because the label is empty, but should the condition return false and do nothing?

    Anyway for the time being i first load all labels with a "." and the test to see if its diferent...That works but the dots are
    Ugly!



    Update: Replaced the "." with a space and it works...I'll stick with it!!
     
    Last edited: May 24, 2007
  2. Erel

    Erel Administrator Staff Member Licensed User

    What is the value of 'selected'?
     
  3. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I suspect that 'selected' has no value, try inserting a MsgBox(selected) prior to the If statement.
    How are you assigning the value for 'selected'??

    Regards,
    RandomCoder
     
  4. specci48

    specci48 Well-Known Member Licensed User

    Could it be a Bug in the LinkLabel library? Since you use the lable_click event you are not using the "normal" label functions.

    Maybe someone could have a look a the source-file hoffi provided.

    specci48
     
  5. Cableguy

    Cableguy Expert Licensed User

    Thank Guys...

    No i was not using the linklabel, as i worked around that with the mouse event...

    My logical was:

    if mouse down xy in area of label1 then
    label1.fontcolor red
    selected="label1"
    else if....and so on
    at the end I passed the labels text using Control(selected).text

    as some of the labels wre not beeing populated their value remained "" and thus the error, worked around by first inserting a space in every label before populating....
     
  6. RandomCoder

    RandomCoder Well-Known Member Licensed User

    CableGuy,

    I understand that you've worked round the problem now :sign0060:, but I've passed text to labels created at run-time with null text value and not experienced any problems so I think that there must be some other underlying problem in your code or installation :confused:

    Try this and see if it works for you...

    Code:
    Sub Globals

    End Sub

    Sub App_Start
       AddForm(
    "Form1","LABEL TESTER")
       AddButton(
    "Form1","ClickMe",50,50,100,20," CLICK ME")
       AddLabel(
    "Form1","TestLabel",50,100,100,20,"")
       Form1.Show
    End Sub

    Sub ClickMe_Click
       Selected=
    "TestLabel"
       
    Control(Selected).Text="Works for me!"
    End Sub
    Is it possible that you're using the variable 'Selected' somewhere else in your code??

    Regards,
    RandomCoder
     
Loading...