Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

VB 6 Code Help Urgent

Status
Not open for further replies.

Suraj143

Active Member
I'm entering a number between 0-255 in the text box.I want to send this number to PIC via serial port when the command button clicks.

The problem is, it only send numbers between 1 to 9.From 10 onwards it won't send because the VB6 thinks it is more than 1 character.

I want to send the byte out.

Code:
Private Sub Command1_Click()
MSComm1.Output = Text1.Text
End Sub
 
Hi that worked,but the problem is the user always needs to write 48,49,50 etc...

I need to write 0,1,2,3 in the text box & needs to send data.

What VB code I have to write?

In simply user will write a number between 1-16 in the text box & the channel number must be saved that value.Thats it :)
Code:
Recieve_DATA	movf	RCREG,W			; yes, data from master
		andlw	b'01111111'
		movwf	RC_Buffer
		;
		movlw	30h
		subwf	RC_Buffer,W		; check channel number
		andlw	b'00011111'
		movwf	Channel_Byte		; *********
 
VB shouldn't be having any trouble sending multiple characters. e.g. mscomm1.Output = "123" will send three characters: '1', '2', '3'. The most likely cause to you not receiving multiple characters is due to your receiver code being invalid.

If you didn't want to have to worry about framing the data you send, you can do as Ian suggested and send a single character having a value between 0-255, i.e. mscomm1.Output = chr(val(text1.Text)). Then you only have to receive a single byte. The manner in which you extract data from that byte is up to you.
 
Last edited:
When you say you have multiple numbers ... Is there a delimiter? ie.. 1,2,3 separated by comma's.

If that is the case you need a simple parser.... lets assume we have the string "55,22,128,33" in text1.text

If you use
Code:
x = InStr( text1.text, ",")
X will contain the position of the first comma ie.. 2
Then strip off the last
Code:
1stno = left( text1.text,2)
should yield 1stno = "55"
re-adjust text1.text to get the second
Code:
y = InStr(x+1, text1.text, ",")
Then retrieve
Code:
2ndno =mid(x+1 text1.text,y)
should yield 2ndno = "22"
re-adjust text1.text to get the second
Code:
z = InStr(y+1, text1.text, ",")
Then retrieve
Code:
3rdno =mid(y+1 text1.text,z)
should yield 3rdno = "128"
And so on...
 
Hello friends I think you still did not get what I mean.

I'm entering a number in the text box.There is no any delimiter or commas.I'm entering a number between 1 to 16 thats it.

Ex:
I type 1 & I press command button then it must send 1
I type 2 & I press command button then it must send 2
I type 3 & I press command button then it must send 3
I type 10 & I press command button then it must send 10
I type 16 & I press command button then it must send 16

So this value must be saved in PIC thats it.The problem I'm facing is, from 1 to 9 the PIC will receive nicely & from 10 onwards it will send some other value.
 
The 'number' in the textbox is actually a text string. Take that string and change it into a value. Will look something like:
NumberToSend = Val(TextBox.Text)
 
The 'number' in the textbox is actually a text string. Take that string and change it into a value. Will look something like:
NumberToSend = Val(TextBox.Text)

It still cannot send number 10 onwards :(
Code:
Private Sub Command1_Click()
Dim val2 As Byte
val2 = Val(Text2.Text)
MSComm1.Output =  val2 
End Sub
 

Attachments

  • Number Send.PNG
    Number Send.PNG
    753 bytes · Views: 169
Because of the way your pic code is written you need to send a single byte.

Try,
Code:
Private Sub Command1_Click()
    MSComm1.Output =  chr(Val(Text2.Text)+48)
End Sub

Mike.
 
Because of the way your pic code is written you need to send a single byte.

Try,
Code:
Private Sub Command1_Click()
    MSComm1.Output =  chr(Val(Text2.Text)+48)
End Sub

Mike.

Brilliant it worked well.Thats the code I wanted.

Thank you very much Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top