Object Reference not set to an instance of an object

Hello,

i´ve got a problem with adding events

my code:

for example: I want to add a Scroolbar ("ScroolBar1") on a TabControl (tbc2)


'ScrollBar1
' Create
ScrollBar1.New1("Form1",0,0,10,245,true)
ScrollBar1.Maximum = 110
ScrollBar1.Minimum = 0
'Add ScroolBar1 on tabControl
tbc2.AddControl(Scrollbar1.ControlRef,0,222,0)

'Event
AddEvent("Scrollbar1",ValueChanged,"ScrollBar1EventValueChanged")



Sub ScrollBar1EventValueChanged
tbc2Label1.Top = 15 - ScrollBar1.Value
tbc2Label2.Top = 27 - ScrollBar1.Value
tbc2Label3.Top = 59 - ScrollBar1.Value
tbc2Label4.Top = 91 - ScrollBar1.Value
tbc2Label5.Top = 150 - ScrollBar1.Value
tbc2Label6.Top = 162 - ScrollBar1.Value
tbc2Label7.Top = 194 - ScrollBar1.Value
tbc2Label8.Top = 226 - ScrollBar1.Value
tbc2Label9.Top = 278 - ScrollBar1.Value
tbc2LabelA.Top = 130 - ScrollBar1.Value
tbc2LabelB.Top = 265 - ScrollBar1.Value
tbc2LabelC.Top = 317 - ScrollBar1.Value

tbc2textbox2.Top = 39 - ScrollBar1.Value
tbc2textbox3.Top = 71 - ScrollBar1.Value
tbc2textbox4.Top = 105 - ScrollBar1.Value
tbc2textbox5.Top = 174 - ScrollBar1.Value
tbc2textbox6.Top = 206 - ScrollBar1.Value
tbc2textbox7.Top = 238 - ScrollBar1.Value
tbc2textbox8.Top = 290 - ScrollBar1.Value

End Sub

i get the message: object reference not set to an instance


it doesn´t happen only with this event....the same happens with the next event i try to add!


'Textbox "tbc2textbox2"
' Create
AddTextBox("form1","tbc2textbox2",0,0,150,15,"0")
tbc2textbox2.Color = cGray
tbc2textbox2.FontColor = CBlue
' Add TextBox on tabControl
tbc2.AddControl("tbc2textbox2",0,15,39)
tbc2textbox2.BringtoFront
' Events AddEvent("tbc2textbox2",LostFocus,"tbc2textbox2LostFocus")

Sub tbc2textbox2LostFocus
tbc2LabelA.Text = tbv2textbox2.Text + tbv2textbox3.Text +tbv2textbox4.text
End Sub


I hope someone can help me!

:sign0085:


Karl
 
hello,

thank´s for your answer. I suppose, that i unfortunately made this "extra space".

in real there is no space in the sub


AddEvent("Scrollbar1",ValueChanged,"ScrollBar1EventValueChanged")


it would be a help, when you could tell me, what the error message "object reference not set to an instance" means

Thanks

Karl
 
i recognize that there still is this extra space posted in my second message... i don´t know why!

so the name of the sub is correct without this space!

AddEvent("Scrollbar1",ValueChanged,"ScrollBar1EventValueChanged") (without space)
 

Cableguy

Expert
Licensed User
for example: I want to add a Scroolbar ("ScroolBar1") on a TabControl (tbc2)
As far as I'm aware, it is NOT possible to add a control, to another control (panels excluded)...
So instead of adding the scrool bar to the tabcontrol, why not add it to the form and make it visible when needed, bringing it to front as well?
 

willisgt

Active Member
Licensed User
Monster, what's the objective here? It looks as though you're trying to scroll through a set of controls; can you give us a little more insight as what you're actually trying to accomplish?

Gary
 
Hi,

thank´s for your answeres and tries to help me. Here you have the part of the code, which doesn´t work... i hope it will be better to understand
 

Attachments

Erel

Administrator
Staff member
Licensed User
The Sub beginning and end do not match (nested subs are not supported) :
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    Form1.Show
    
    'TabControl - für Knopf "Tool-Bilanzanalyse"
       tbc2.New1("Form1",0,0,240,270)
       tbc2.AddTabPage("Aktiva")
       tbc2.AddTabPage("Passiva")
       tbc2.AddTabPage("GuV")
       tbc2.SetColor(0,cgray)
    tbc2.SetColor(1,cgray)
    tbc2.SetColor(2,cgray)
    
    'Bilanzanalyse - AKTIVA
    
    'LABEL


    ' Label "ALabel1"  // "A Anlagevermögen"
        ' Initialisierung
            AddLabel("form1","tbc2Label1",0,0,150,15,"A Anlagevermögen")
            tbc2Label1.Color = cGray
            tbc2Label1.FontColor = cYellow
        ' Platzierung auf TabControl
            tbc2.AddControl("tbc2Label1",0,2,15)
    
    
    'ScrollBar1 auf AKTIVA
        ' Initialisierung
            ScrollBar1.New1("Form1",0,0,10,245,true)
            ScrollBar1.Maximum = 110
            ScrollBar1.Minimum = 0
        'Plazierung auf TabControl
            tbc2.AddControl(Scrollbar1.ControlRef,0,222,0)
        'Event
            AddEvent("Scrollbar1",ValueChanged,"SBE_ValueChanged")
            
[B]Sub SBE_ValueChanged
       [/B] tbc2Label1.Top = 15 - ScrollBar1.Value[B]
End Sub    

End Sub[/B]
 
Top