两件相同的代码做不同的事情 [英] 2 pieces of the same code doing different things

查看:57
本文介绍了两件相同的代码做不同的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这两个代码片段:


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


结束子





Private Sub s_OnImReceived(ByVal session as AccCoreLib.AccSession ,ByVal

imSession作为AccCoreLib.IAccImSession,ByVal发件人作为

AccCoreLib.IAccParticipant,ByVal im As AccCoreLib.IAccIm)处理

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

底部片段有效,顶部不行。唯一不同的是

,底部的一个直接在事件中工作,而另一个片段工作

来自该事件调用的方法.....我的所有对象和变量有一个

的值,这些值是正确的(在每个情况下调试它之后

可以想象)我不能让顶级代码片段起作用。我只是好奇为什么两个

件相同的代码不一样.....我使用VB 2005 btw .... ive

联系了制造商SDK这是在看看它是否有问题

那里,所以我也在这里询问它是否与我的

代码的东西.....不应该这两个片段工作一样吗?我错过了什么?谢谢


-

-iwdu15

解决方案

在第一个你没有使用临时工具:


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

-tom


iwdu15 ha scritto:


我有这两个代码片段:


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


结束子





Private Sub s_OnImReceived(ByVal session as AccCoreLib.AccSession ,ByVal

imSession作为AccCoreLib.IAccImSession,ByVal发件人作为

AccCoreLib.IAccParticipant,ByVal im As AccCoreLib.IAccIm)处理

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


底部片段有效,顶部片段无效。唯一不同的是

,底部的一个直接在事件中工作,而另一个片段工作

来自该事件调用的方法.....我的所有对象和变量有一个

的值,这些值是正确的(在每个情况下调试它之后

可以想象)我不能让顶级代码片段起作用。我只是好奇为什么两个

件相同的代码不一样.....我使用VB 2005 btw .... ive

联系了制造商SDK这是在看看它是否有问题

那里,所以我也在这里询问它是否与我的

代码的东西.....不应该这两个片段工作一样吗?我错过了什么?谢谢


-

-iwdu15


你的最后一行代码第一部分:


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


你不应该使用temp吗?你没有用str做任何事情。


Tom

iwdu15写道:


>我有这2个代码片段:


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


结束子



Private Sub s_OnImReceived(ByVal session as AccCoreLib.AccSession,ByVal
imSession作为AccCoreLib.IAccImSession,ByVal发送者作为
AccCoreLib.IAccParticipant,ByVal im As AccCoreLib.IAccIm)处理
s.OnImReceived


Dim str As String = im.GetConvertedText(解码)

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

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


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


End Sub

底部片段有效,顶部不行。唯一不同的是底层的一个直接在事件中工作,而另一个片段从一个从该事件调用的方法工作.....所有我的对象和变量都有一个
值,这些值是正确的(在可以想象的每个情况下进行调试之后)我无法获得最佳代码片段。我只是好奇为什么两个
相同的代码不同工作.....我使用VB 2005顺便说一句....我已经联系SDK的制造商这是在看看它是否一个问题
那么,我也问这里看看它的代码是什么......这些两个片段的工作原理是否相同?我错过了什么?谢谢


在第二个我正在创建变量str的副本并将

它放入temp。这是因为后来我会添加代码来操纵temp和我想要保留原始的b $ b。第一个我不打算这样做。我没有使用临时变量尝试过它b $ b我做了同样的事情

-

-iwdu15

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

解决方案

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


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


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


这篇关于两件相同的代码做不同的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆