473,699 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Captio n = Mid(Data, 7)
Exit Sub
End If

List1.AddItem (Data)

help is appreciated.
Dec 30 '06 #1
11 11166
On Sat, 30 Dec 2006 12:19:20 +0100, "313 Games"
<in*****@invali d.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.Captio n = 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*****@invali d.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

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

Similar topics

3
14940
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
5
2838
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 invisible() { alert("invisible() called"); } }
2
7674
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 like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
2
12685
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
5108
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 constructors (these three I knew about), but also conditional function definitions, as described in http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Defining_Functions ]. An example: function fun() {
3
3651
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' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
2
5324
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: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
28
4318
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
2128
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
3217
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 bastard so posting it before I forgot again... By taking this minimum code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head>
0
8705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9054
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8941
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8896
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7784
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.