473,403 Members | 2,183 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,403 software developers and data experts.

2 pieces of the same code doing different things

hi, i have these 2 code snippets:

Public Sub ImRec(ByVal IM As IAccIm, ByVal Sender As IAccUser)

Dim str As String = IM.GetConvertedText(DECODE)

Dim temp As String = str

temp = temp.Remove(temp.IndexOf("<body>"), 6)
temp = temp.Remove(temp.IndexOf("</body>"), 7)

Me.webRecv.DocumentText += "<br>" & str

End Sub

and

Private Sub s_OnImReceived(ByVal session As AccCoreLib.AccSession, ByVal
imSession As AccCoreLib.IAccImSession, ByVal sender As
AccCoreLib.IAccParticipant, ByVal im As AccCoreLib.IAccIm) Handles
s.OnImReceived

Dim str As String = im.GetConvertedText(decode)

str = str.Remove(str.IndexOf("<body>"), 6)
str = str.Remove(str.IndexOf("</body>"), 7)

Me.webrecv.DocumentText += "<br>" & str

End Sub
the bottom snippet works, the top one doesnt. the only thing different is
that the bottom one works directly in the event while the other snippet works
from a method called from that event.....all my objects and variables have a
value, these values are correct (after debugging it under every surcumstance
imaginable) i cant get the top snippet to work. im just curious why two
pieces of the same code dont work the same.....im using VB 2005 btw....ive
contacted the manufacturer of the SDK this is in to see if its a problem
there, so im also asking here to see if its something with my
code.....shouldnt these two snippets work the same? what am i missing? thanks

--
-iwdu15
Jul 31 '06 #1
15 1543
in the first one you are not using temp:

Me.webRecv.DocumentText += "<br>" & temp
-tom

iwdu15 ha scritto:
hi, i have these 2 code snippets:

Public Sub ImRec(ByVal IM As IAccIm, ByVal Sender As IAccUser)

Dim str As String = IM.GetConvertedText(DECODE)

Dim temp As String = str

temp = temp.Remove(temp.IndexOf("<body>"), 6)
temp = temp.Remove(temp.IndexOf("</body>"), 7)

Me.webRecv.DocumentText += "<br>" & str

End Sub

and

Private Sub s_OnImReceived(ByVal session As AccCoreLib.AccSession, ByVal
imSession As AccCoreLib.IAccImSession, ByVal sender As
AccCoreLib.IAccParticipant, ByVal im As AccCoreLib.IAccIm) Handles
s.OnImReceived

Dim str As String = im.GetConvertedText(decode)

str = str.Remove(str.IndexOf("<body>"), 6)
str = str.Remove(str.IndexOf("</body>"), 7)

Me.webrecv.DocumentText += "<br>" & str

End Sub
the bottom snippet works, the top one doesnt. the only thing different is
that the bottom one works directly in the event while the other snippet works
from a method called from that event.....all my objects and variables have a
value, these values are correct (after debugging it under every surcumstance
imaginable) i cant get the top snippet to work. im just curious why two
pieces of the same code dont work the same.....im using VB 2005 btw....ive
contacted the manufacturer of the SDK this is in to see if its a problem
there, so im also asking here to see if its something with my
code.....shouldnt these two snippets work the same? what am i missing? thanks

--
-iwdu15
Jul 31 '06 #2
Your last line of code in the first piece:

Me.webRecv.DocumentText += "<br>" & str

Shouldn't you be using "temp"? You haven't done anything with "str".

Tom
iwdu15 wrote:
>hi, i have these 2 code snippets:

Public Sub ImRec(ByVal IM As IAccIm, ByVal Sender As IAccUser)

Dim str As String = IM.GetConvertedText(DECODE)

Dim temp As String = str

temp = temp.Remove(temp.IndexOf("<body>"), 6)
temp = temp.Remove(temp.IndexOf("</body>"), 7)

Me.webRecv.DocumentText += "<br>" & str

End Sub

and

Private Sub s_OnImReceived(ByVal session As AccCoreLib.AccSession, ByVal
imSession As AccCoreLib.IAccImSession, ByVal sender As
AccCoreLib.IAccParticipant, ByVal im As AccCoreLib.IAccIm) Handles
s.OnImReceived

Dim str As String = im.GetConvertedText(decode)

str = str.Remove(str.IndexOf("<body>"), 6)
str = str.Remove(str.IndexOf("</body>"), 7)

Me.webrecv.DocumentText += "<br>" & str

End Sub
the bottom snippet works, the top one doesnt. the only thing different is
that the bottom one works directly in the event while the other snippet works
from a method called from that event.....all my objects and variables have a
value, these values are correct (after debugging it under every surcumstance
imaginable) i cant get the top snippet to work. im just curious why two
pieces of the same code dont work the same.....im using VB 2005 btw....ive
contacted the manufacturer of the SDK this is in to see if its a problem
there, so im also asking here to see if its something with my
code.....shouldnt these two snippets work the same? what am i missing? thanks
Jul 31 '06 #3
well in the second one i am creating a copy of the variable str and putting
it into temp. this is because later i will add code to manipulate temp and i
want to keep the original. the first one i wasnt planning on doing that. i
have tried it without using the temp variable and it does the same thing
--
-iwdu15
Jul 31 '06 #4
Hmmmm.
as it has been pointed out, the 2 snipptes are not the same. In the first
you apply the 2 remove calls to 'temp' but appent 'str'. In the second, you
apply the 2 remove calls to 'str' and append 'str'. Maybe this is just a
typo in the explanation (example) in which case it might help if you were to
explain in detail what 'doesn't work' means.
--
Terry
"iwdu15" wrote:
well in the second one i am creating a copy of the variable str and putting
it into temp. this is because later i will add code to manipulate temp and i
want to keep the original. the first one i wasnt planning on doing that. i
have tried it without using the temp variable and it does the same thing
--
-iwdu15
Jul 31 '06 #5
sure, il explain. the first snippet is from one app where an event calls the
method, passing in all needed variables. i create an exact copy of the
variable which contains the text i want to add to the WebBrowser document.
Later i will add code to add in a username and Time received to the Temporary
variable, this is why i do that. So now i have two variables which are
exactly trhe same, str and temp. i remove the "<body>" tags so the text will
line up with the left side of the WebBrowser control and not be floating
around the middle. then i attempt to add the text to the WebBrowser.
occaisionally it will add the very first thing i pass it, but after that
nothing. The html is correct, i have triple checked it. what ends up almost
always happening is when it hits this line:

Me.webRecv.DocumentText += "<br>" & str

in the first code snippet, it goes over it like it does the code, but the
text is never added to the webbrowser. no error, nothing. I have changed it
to

Me.webRecv.DocumentText += "<br>" & temp

but still nothing. now to the second snippet.

the second snippet is in a different application (and yes i have tried
putting my code in a new project, i have also tried completely recoding my
project but the first part of code still doesnt work). in this app, the code
is added directly from the event that is raised. the HTML code is exactly the
same as the first code snippets, but this time it is added to the WebBrowser
perfectly fine. The text shows up exactly how its supposed to.

in the first snippet, i am creating a copy and removing the body tags then
attempting to add it and it doesnt work, in the second one i cut the body
tags out of the first variable and add it to the WebBrowser and it works
perfectly. Would this be an issue? hope this makes a little more sense
now....thanks for your help
--
-iwdu15
Jul 31 '06 #6
Place a break on the line

Me.webRecv.DocumentText += "<br>" & temp

to see if it is executed at all.

-t
iwdu15 ha scritto:
sure, il explain. the first snippet is from one app where an event calls the
method, passing in all needed variables. i create an exact copy of the
variable which contains the text i want to add to the WebBrowser document.
Later i will add code to add in a username and Time received to the Temporary
variable, this is why i do that. So now i have two variables which are
exactly trhe same, str and temp. i remove the "<body>" tags so the text will
line up with the left side of the WebBrowser control and not be floating
around the middle. then i attempt to add the text to the WebBrowser.
occaisionally it will add the very first thing i pass it, but after that
nothing. The html is correct, i have triple checked it. what ends up almost
always happening is when it hits this line:

Me.webRecv.DocumentText += "<br>" & str

in the first code snippet, it goes over it like it does the code, but the
text is never added to the webbrowser. no error, nothing. I have changed it
to

Me.webRecv.DocumentText += "<br>" & temp

but still nothing. now to the second snippet.

the second snippet is in a different application (and yes i have tried
putting my code in a new project, i have also tried completely recoding my
project but the first part of code still doesnt work). in this app, the code
is added directly from the event that is raised. the HTML code is exactly the
same as the first code snippets, but this time it is added to the WebBrowser
perfectly fine. The text shows up exactly how its supposed to.

in the first snippet, i am creating a copy and removing the body tags then
attempting to add it and it doesnt work, in the second one i cut the body
tags out of the first variable and add it to the WebBrowser and it works
perfectly. Would this be an issue? hope this makes a little more sense
now....thanks for your help
--
-iwdu15
Jul 31 '06 #7
it is executed, all variables have values, all variables have correct
values....everything should work but it doesnt
--
-iwdu15
Jul 31 '06 #8
Ok, lets back up for a minute. Do both methods work when placed directly in
the event? Do both methods fail when placed in a called sub?
--
Terry
"iwdu15" wrote:
it is executed, all variables have values, all variables have correct
values....everything should work but it doesnt
--
-iwdu15
Jul 31 '06 #9
no, the first one still does not work when placed in the event and the second
snippet still works when placed in a separate method and called from the event
--
-iwdu15
Aug 1 '06 #10
Well you got me stumped! Is option strict on? I think that if I was you, I
would use ILDASM for the two snippits and see if I could spot what was
happening.

--
Terry
"iwdu15" wrote:
no, the first one still does not work when placed in the event and the second
snippet still works when placed in a separate method and called from the event
--
-iwdu15
Aug 1 '06 #11
whats ILDASM? how would this help with my....unusual problem?
--
-iwdu15
Aug 1 '06 #12
ILDASM is the IL DisASseMbler. It shows the IL code emitted by the
compiler.

Can you post a short but complete sample that demonstrates the problem?

iwdu15 wrote:
whats ILDASM? how would this help with my....unusual problem?
--
-iwdu15
Aug 1 '06 #13
my first post has everything thats involved in this....il try to fully
explain my situation..

im creating an AIM Custom Client using the SDK that AOL kindly provided.
When an IM is received, the event OnImReceived is fired. In one app (which is
very very basic) handles the IM and and enters the text into the WebBrowser
control (the AIM network formats text in an HTML like formatting, so i
figured this control would be best). this works fine, the text is added with
no difficulty. However, in my more complete application, the IM is received
in the same event in the same exact way. however, instead of beign added to a
control right away, the object is passed to the form that shows the Instant
Messages. this form then passes this same variable to a user control i made.
the object is not changed or even accessed in any way until it reaches my
custom control, where then my first snippet method is called. hope this helps
understand whats going on

i have copied and pasted the code form the working one to the not working
one and it still wont work....i have no idea whats going on here.....when i
get home il check the ILDASM stuff, but (Chris and anyone that was wondering)
i hope this helps in some way....
--
-iwdu15
Aug 1 '06 #14
heres the ILDASM for setting the text

Broken App:

IL_00cc: callvirt instance class
[System.Windows.Forms]System.Windows.Forms.WebBrowser
AimCC.ctrlIM::get_webRecv()
IL_00d1: stloc.s VB$t_ref$S0
IL_00d3: ldloc.s VB$t_ref$S0
IL_00d5: ldloc.s VB$t_ref$S0
IL_00d7: callvirt instance string
[System.Windows.Forms]System.Windows.Forms.WebBrowser::get_DocumentText( )
IL_00dc: ldstr "<br>"
IL_00e1: ldloc.0
IL_00e2: call string [mscorlib]System.String::Concat(string,
string,
string)
IL_00e7: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.WebBrowser::set_DocumentText( string)

working app:

IL_0054: callvirt instance class
[System.Windows.Forms]System.Windows.Forms.WebBrowser
WindowsApplication1.Form1::get_webrecv()
IL_0059: stloc.1
IL_005a: ldloc.1
IL_005b: ldloc.1
IL_005c: callvirt instance string
[System.Windows.Forms]System.Windows.Forms.WebBrowser::get_DocumentText( )
IL_0061: ldstr "<br>"
IL_0066: ldloc.0
IL_0067: call string [mscorlib]System.String::Concat(string,
string,
string)
IL_006c: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.WebBrowser::set_DocumentText( string)


the only difference seems to be this:

IL_00d1: stloc.s VB$t_ref$S0
IL_00d3: ldloc.s VB$t_ref$S0
IL_00d5: ldloc.s VB$t_ref$S0
any ideas?

--
-iwdu15
Aug 1 '06 #15
iwdu15 wrote:
my first post has everything thats involved in this....il try to fully
explain my situation..
Yes, but your first post has a bug:
Public Sub ImRec(ByVal IM As IAccIm, ByVal Sender As IAccUser)

Dim str As String = IM.GetConvertedText(DECODE)
Here you get a string
>
Dim temp As String = str
You assign the string to a temp variable
temp = temp.Remove(temp.IndexOf("<body>"), 6)
temp = temp.Remove(temp.IndexOf("</body>"), 7)
You manipulate the temp variable...
Me.webRecv.DocumentText += "<br>" & str

End Sub
But then you assign the original string back to DocumentText!! You
should assign the temp variable back like this:

Me.webRecv.DocumentText += "<br>" & temp

Aug 2 '06 #16

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

Similar topics

45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
8
by: Wikicodia Admin | last post by:
Dears, Wikicodia is a wiki based project for sharing code snippets. We're collecting large number of code snippets for all code-based programming languages, scripts, shells and consoles. We wish...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
29
by: Virtual_X | last post by:
As in IEEE754 double consist of sign bit 11 bits for exponent 52 bits for fraction i write this code to print double parts as it explained in ieee754 i want to know if the code contain any...
15
by: fyi | last post by:
My new blog on bits and pieces of PHP coding. http://bitspiecesphp.blogspot.com/ Have used all of them. Hope they're as useful to others: Use PHP to track email sender from your web site...
4
by: David | last post by:
Hi list. Do test-driven development or behaviour-driven development advocate how to do higher-level testing than unit testing? types of testing: unit integration system
6
by: Christopher | last post by:
I've seen various ways of doing this, but what I want is to be able to take a base class pointer and know which derived class to cast to. For example I am going to make a base light class, that...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.