473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Mid function

hi,

ive got a question. im making an chat program with server and client using
vb 6. but now my problem is, i want to set a topic in each server.

i want to send the data from the server to all the clients connected, and
the client can see: ow, a topic, then /topic Bla bla bla

This is my code, maybe its less complicated.

Dim Data As String
Sock.GetData (Data)

If Mid(Data, 0, 6) = "/topic" Then
lblTopic.Caption = Mid(Data, 7)
Exit Sub
End If

List1.AddItem (Data)

help is appreciated.
Dec 30 '06 #1
11 11148
On Sat, 30 Dec 2006 12:19:20 +0100, "313 Games"
<in*****@invalid.invalidwrote:
>hi,

ive got a question. im making an chat program with server and client using
vb 6. but now my problem is, i want to set a topic in each server.

i want to send the data from the server to all the clients connected, and
the client can see: ow, a topic, then /topic Bla bla bla
>This is my code, maybe its less complicated.

Dim Data As String
Sock.GetData (Data)

If Mid(Data, 0, 6) = "/topic" Then
lblTopic.Caption = Mid(Data, 7)
Exit Sub
End If

List1.AddItem (Data)

help is appreciated.
Mid(Data, 1, 6) = "/topic"

0 instead of 1 will throw an error

Personally I would use Left( Data, 6) = "/topic"

Incidentally Mid$( Data, 1, 6 ) and Left$(Data, 6) are faster, the $
returns a string while without the $ you get a string in a variant.

Dec 30 '06 #2
thanks, it works fine now :)

but now i got another question,
when the winsock sends a message when connected (as client), the server WILL
get it, but without any data in the string sended.

whats the problem? i've tried it on server @ localhost and server @ other
local computer, both didnt work.
Dec 30 '06 #3
On Sat, 30 Dec 2006 12:35:41 +0100, "313 Games"
<in*****@invalid.invalidwrote:
>thanks, it works fine now :)
>but now i got another question,
when the winsock sends a message when connected (as client), the server WILL
get it, but without any data in the string sended.
>whats the problem? i've tried it on server @ localhost and server @ other
local computer, both didnt work.
Beats me - that is a bit of an open question.

Dec 30 '06 #4
Sock.GetData (Data)
List1.AddItem (Data)
You already have your answer to the question you asked; however, I wanted to
point something out about the above two lines of code from your posting. Get
out of the habit you apparently have of encasing arguments for methods and,
I will guess by extension, subroutine calls in parentheses. Unlike other
languages which **require** parentheses around all arguments, VB doesn't. In
the above statements, it won't cause any problem; but there are cases where
surrounding your arguments in parentheses will cause an error to occur or,
worse yet, no error will be generated but incorrect results will be
generated. You should only use parentheses around arguments where they are
required **by syntax**. For arguments to methods (such as above),
parentheses are never required; for subroutines, they are required only when
the CALL keyword is used to call the subroutine.

The reason for my caution is that VB treats things in parentheses as
expressions to be evaluated (even if that thing is not really considered an
expression, such as a variable name). If your method or subroutine call
require two arguments, encasing both of them in one set of parentheses will
force an error to be generated as a comma separated list is not a proper
expression that VB can evaluate. The real problem comes with arguments that
are supposed to be passed ByRef (by reference)... a parentheses-encased
argument will force VB to pass the memory address of the temporary memory
location used to evaluate the expression and that is what the subroutine
will use to write back its ByRef argument to... which means the original
variable which was supposed to be updated by the subroutine will not be (no
error will be generated, but your results will be incorrect). Here is a
short example to show you what I mean. Paste the following into new
project's Form's code window...

Private Sub Form_Load()
Dim MyNumber As Double
' Set the value of MyNumber to a value, say 4
MyNumber = 4
' This next statement will generate the correct value
' of 16 (note that no parentheses are used).
SquareMe myNumber
MsgBox MyNumber)
' Reset the value of variable back to its original value
MyNumber = 4
' This next statement will generate the wrong value
' because it is surrounded in parentheses.
SquareMe (myNumber)
MsgBox MyNumber
End Sub

Sub SquareMe(ByRef X As Double)
X = X * X
End Sub

The SquareMe subroutine takes its passed value, multiplies it by itself and
then uses the fact that it was passed ByRef to send the updated value back
to the calling code by assigning the new value directly to the passed
argument. When no parentheses surround the argument, the variable is updated
correctly; but when the argument is surrounded by parentheses, the variable
does not get updated (the calculated variable was returned to the temporary
memory location where the "expression" was evaluated at before being passed
to the subroutine instead of the actual memory address of the variable
itself.

You will be doing yourself a big favor if you break the habit you have of
placing parentheses around arguments, now, before it becomes too ingrained a
habit to break later on.

Rick


Dec 30 '06 #5

"Rick Rothstein (MVP - VB)" <ri************@NOSPAMcomcast.netwrote in message
news:bM******************************@comcast.com. ..
>
You will be doing yourself a big favor if you break the habit you have of
placing parentheses around arguments, now, before it becomes too ingrained a
habit to break later on.
I have adopted the opposite habit, that of always using Call with subroutines,
and the parentheses along with it.

My main reason? In the course of development, many subs turn into functions -
that is, a return value from the procedure becomes useful, even if it is just a
boolean indicating success or failure.

If I have written Call Test(X,Y), it is then easy to turn it into Z = Test(X,Y).

I suspect that I also like seeing arguments listed in parentheses when reading
code, and it is the more common standard in other languages.

Dec 30 '06 #6
>You will be doing yourself a big favor if you break the habit you have of
>placing parentheses around arguments, now, before it becomes too
ingrained a habit to break later on.

I have adopted the opposite habit, that of always using Call with
subroutines, and the parentheses along with it.
I was originally going to write that this option doesn't exist with Methods,
but it seems I would have been wrong... this is a new one for me, but I
tried using Call with a Method and it worked seems to work fine. For
example...

Call Me.Move(1000, 2000, 3000, 4000)

While you didn't post this directly, your post did lead me to learn
something new today. Thanks.

Rick
Dec 30 '06 #7
>>You will be doing yourself a big favor if you break the habit you have
>>of placing parentheses around arguments, now, before it becomes too
ingrained a habit to break later on.

I have adopted the opposite habit, that of always using Call with
subroutines, and the parentheses along with it.

I was originally going to write that this option doesn't exist with
Methods, but it seems I would have been wrong... this is a new one for me,
but I tried using Call with a Method and it worked seems to work fine. For
example...

Call Me.Move(1000, 2000, 3000, 4000)

While you didn't post this directly, your post did lead me to learn
something new today. Thanks.
Oh! I should have mentioned... personal preference... I still prefer
**not** to use the Call keyword.

Rick
Dec 30 '06 #8

"Rick Rothstein (MVP - VB)" <ri************@NOSPAMcomcast.netwrote in message
news:IO******************************@comcast.com. ..
>
Oh! I should have mentioned... personal preference... I still prefer **not**
to use the Call keyword.
Do you know of anything I should know as a reason not to, or is that just
personal preference?
Dec 31 '06 #9
>Oh! I should have mentioned... personal preference... I still prefer
>**not** to use the Call keyword.

Do you know of anything I should know as a reason not to, or is that just
personal preference?
Strictly a personal preference... to me, the Call keyword is in the same
category as the (non-object oriented) Let keyword... it is not required so
it is superfluous.

Rick
Dec 31 '06 #10
thankyou , now everything works fine!! :D

grtz,
313!

"Rick Rothstein (MVP - VB)" <ri************@NOSPAMcomcast.netschreef in
bericht news:bM******************************@comcast.com. ..
> Sock.GetData (Data)
List1.AddItem (Data)

You already have your answer to the question you asked; however, I wanted
to point something out about the above two lines of code from your
posting. Get out of the habit you apparently have of encasing arguments
for methods and, I will guess by extension, subroutine calls in
parentheses. Unlike other languages which **require** parentheses around
all arguments, VB doesn't. In the above statements, it won't cause any
problem; but there are cases where surrounding your arguments in
parentheses will cause an error to occur or, worse yet, no error will be
generated but incorrect results will be generated. You should only use
parentheses around arguments where they are required **by syntax**. For
arguments to methods (such as above), parentheses are never required; for
subroutines, they are required only when the CALL keyword is used to call
the subroutine.

The reason for my caution is that VB treats things in parentheses as
expressions to be evaluated (even if that thing is not really considered
an expression, such as a variable name). If your method or subroutine call
require two arguments, encasing both of them in one set of parentheses
will force an error to be generated as a comma separated list is not a
proper expression that VB can evaluate. The real problem comes with
arguments that are supposed to be passed ByRef (by reference)... a
parentheses-encased argument will force VB to pass the memory address of
the temporary memory location used to evaluate the expression and that is
what the subroutine will use to write back its ByRef argument to... which
means the original variable which was supposed to be updated by the
subroutine will not be (no error will be generated, but your results will
be incorrect). Here is a short example to show you what I mean. Paste the
following into new project's Form's code window...

Private Sub Form_Load()
Dim MyNumber As Double
' Set the value of MyNumber to a value, say 4
MyNumber = 4
' This next statement will generate the correct value
' of 16 (note that no parentheses are used).
SquareMe myNumber
MsgBox MyNumber)
' Reset the value of variable back to its original value
MyNumber = 4
' This next statement will generate the wrong value
' because it is surrounded in parentheses.
SquareMe (myNumber)
MsgBox MyNumber
End Sub

Sub SquareMe(ByRef X As Double)
X = X * X
End Sub

The SquareMe subroutine takes its passed value, multiplies it by itself
and then uses the fact that it was passed ByRef to send the updated value
back to the calling code by assigning the new value directly to the passed
argument. When no parentheses surround the argument, the variable is
updated correctly; but when the argument is surrounded by parentheses, the
variable does not get updated (the calculated variable was returned to the
temporary memory location where the "expression" was evaluated at before
being passed to the subroutine instead of the actual memory address of the
variable itself.

You will be doing yourself a big favor if you break the habit you have of
placing parentheses around arguments, now, before it becomes too ingrained
a habit to break later on.

Rick


Jan 2 '07 #11
argh, too fast happy :-(

a second connection to the server program, and it does not send any data.
for that to fix, i have to restart my server. ???

313.
Jan 2 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
4
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.