Click event from code

Click event from code

Postby LittleHarry » Thu Sep 19, 2013 2:11 am

Henning and Slowdown,
Thank you very much for the help you've given me. I'd like you to know that I don't ask questions as soon as a problem crops up; I try to solve these things myself until I'm sure I just can't find the answer. The old, closed forum is a great help at times.

But here is another question:
I am trying to call a command button click from code, in VB6 I simply type "cmdButton_click", as in
Code: Select all
Sub cmdButton1_click()
 ...
 does stuff
 ...
end sub

sub cmdButton2_click()
 ...
 code to change conditions
 ...
cmdButton1_click
end sub


What is the kBasic equivalent to "cmdButton1_click"?
LittleHarry
 
Posts: 22
Joined: Mon Sep 02, 2013 5:42 pm

Re: Click event from code

Postby Slowdown » Thu Sep 19, 2013 5:55 am

Hi Harry,

There are some events you can use with the Button,
Thefault action is when you (double clicked) on de the button on the Form is that KBasic create this (default one ) in code,
Code: Select all

Private Sub CommandButton1_OnEvent()
 
End Sub

But on the righthandside of the screen you wil find some more evens with you can you with the Button,
EventControl_Button.png
EventControl_Button.png (15.16 KiB) Viewed 365 times

If you need an small example just letme nkow
Kind regards,
Slowdown

OSX 10.8.x, VBox Xp, Ubuntu 32/64 bit, EOS 64 bit
Slowdown
 
Posts: 464
Joined: Sat May 01, 2010 7:11 pm
Location: Netherlands

Re: Click event from code

Postby LittleHarry » Thu Sep 19, 2013 8:29 am

Hi Slowdown
I'm burning the midnight oil here trying to do a couple of things that I think should work, but don't.

I think you misunderstood my previous question.
I don't want to launch a sub cmdButton1_click event by clicking the button. I want to click cmdButton2, run some code, then launch the cmdButton1 click event from code (without actually clicking the button).
The VB6 code I sent does that, but I can't figure out how to do it in kBasic.

Also, what is the equivalent to vbcrlf? I thought it was kbcrlf, but that doesn't work for me. Is there a text box property that allows/disallows multi line input from code?

Cheers,
Harry
LittleHarry
 
Posts: 22
Joined: Mon Sep 02, 2013 5:42 pm

Re: Click event from code

Postby Slowdown » Thu Sep 19, 2013 9:49 am

Hi Harry,
The VB6 code I sent does that, but I can't figure out how to do it in kBasic.

You are probably using a TextBox that is the reason that KbCrlf isn't working.
A TextBox is limited to 1 line only.
There are 2 way's to limit the input of a TextBox.
1) in the Form designer,
Select the Control in this case the TextBox and look in the property window.
TextBox property.png
TextBox property.png (8.05 KiB) Viewed 358 times

2) by Code but this isn't working here KBasic keeps reporting an error when i use that.
Code: Select all
TextBox1.maximum = 25


Below some sample code to call a Button.
I have called my Buttons Button1 and Button2
I also placed a RichTextBox on the Form to show that KbCrlf is working.
Code: Select all
Private Sub Button1_OnEvent()
  TextBox1.Text = "This is button 1" & KbCrlf & "Second line"                      '  KbCrlf isn't working
  RichTextBox1.plainText()
  RichTextBox1.value = "This is button 1" & KbCrlf & "Second line"                 '  KbCrlf is working watch out here it is TextBox1.text =  and RichTextBox.value =
  Button2_OnEvent()
End Sub

Private Sub Button2_OnEvent()
  TextBox1.Text=TextBox1.Text & "Button 2"
  RichTextBox1.value = RichTextBox1.value & KbCrlf & "Button 2"
End Sub
Kind regards,
Slowdown

OSX 10.8.x, VBox Xp, Ubuntu 32/64 bit, EOS 64 bit
Slowdown
 
Posts: 464
Joined: Sat May 01, 2010 7:11 pm
Location: Netherlands

Re: Click event from code

Postby Henning » Thu Sep 19, 2013 12:05 pm

Hi Harry,

First of all, I'm totally against directly calling an event function... 8-)

If you need to run code for ie a commandbutton, use a separate Sub/Function for that code. Then call the executing Sub/Function from the click event or from other code.

Code: Select all
Sub cmdButton1_click()
  ExButton1
end sub

Sub ExButton1()
 ...
 does stuff
 ...
End Sub
sub cmdButton2_click()
 ...
 code to change conditions
 ...
 ExButton1
end sub


This way you can also add parameters to see if called by Click or by code, if you want execution differentiated. ;)

/Henning
Henning
 
Posts: 522
Joined: Fri Aug 13, 2010 6:29 pm

Re: Click event from code

Postby LittleHarry » Thu Sep 19, 2013 3:48 pm

Slowdown,
Thanks, I didn't realise that a text box is restricted to one line in KB. It's working great now.

Henning,
I agree with you now, it dawned on me that creating another sub code is the proper way to go.

Cheers,
Harry
LittleHarry
 
Posts: 22
Joined: Mon Sep 02, 2013 5:42 pm

Re: Click event from code

Postby Slowdown » Thu Sep 19, 2013 7:22 pm

@Harry,
Nice, and again a problem removed ;)
@both,
First of all, I'm totally against directly calling an event function...

Agreed but in the spirit of solving the problem i forgot it 8-)

-off topic-
As promised i did reinstall KBasic and took a dive in a project i wanted to make in Q7B and have to
mention that compiling in KB is lovely fast.
Decided to do the project in KB keeping in mind that i want to port it to Q7B if the time is there.
-edit-
After 2 day's must admit that i like Q7B over KB ;)
A lot of user error's KB will report as 'error in line 0' :shock:
Kind regards,
Slowdown

OSX 10.8.x, VBox Xp, Ubuntu 32/64 bit, EOS 64 bit
Slowdown
 
Posts: 464
Joined: Sat May 01, 2010 7:11 pm
Location: Netherlands


Return to Legacy: KBasic related

Who is online

Users browsing this forum: No registered users and 1 guest

cron