|
-
Apr 15th, 2009, 05:48 AM
#1
Thread Starter
Frenzied Member
Syntax error in string manipulation
Hey,
Some help please!
I am trying an encrypting exercise which takes the txtmessage and encrypts it in characterarray.
IStartAt is the starting point and by taking one character at a time from txtmessage I need to insert it in characterarr\y allowing a gap in between which is IUseGap. KeyGap and Keyfirst will be the next two characters after txtmessage and when insert have no gap in between.
I think the logic I done is good however, I get syntax errors on the red lines.
Please Help me get this right. Many thanks
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsecrettMessage.Click
'Splitletters()
Dim KeyFirst, KeyGap, secretmessage As String
Dim encodestring As String = txtmessage.Text
lStartAt = 200 + lUse5th
Dim lPos As Long
KeyFirst = Asc(encodestring(0))
KeyGap = (Asc(lUseGap))
encodestring += String.Format(KeyFirst + KeyGap)
For lPos = 1 To encodestring.Length
characterarray.Substring(((lPos - 1) * lUseGap) + lStartAt) = encodestring.Substring(lPos - 1)
If (encodestring.Length - 2 = True) Then
characterarray.replace (1Pos+1,KeyFirst)
End If
If (encodestring.Length - 1 = True) Then
characterarray.replace (1Pos+2,KeyGap)
End If
Next
secretmessage = characterarray.ToString
End Sub
Last edited by angelica; Apr 15th, 2009 at 05:51 AM.
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Apr 15th, 2009, 06:07 AM
#2
Re: Syntax error in string manipulation
Where have you declared "characterarray"?
-
Apr 15th, 2009, 06:53 AM
#3
Thread Starter
Frenzied Member
Re: Syntax error in string manipulation
It is declared as Public at the top of Form
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Apr 15th, 2009, 07:02 AM
#4
Re: Syntax error in string manipulation
Hey,
Can you tell us what are the errors that you are getting?
Also, fair enough characterarray is declared as Public at the top of your form, but what is it's type?
Gary
-
Apr 15th, 2009, 07:07 AM
#5
Thread Starter
Frenzied Member
Re: Syntax error in string manipulation
Dim characterarray() As Char
Public Sub Main()
characterarray = RandomGen1.ToCharArray()
===============================================
characterarray.Substring(((lPos - 1) * lUseGap) + lStartAt)
Errror on: Expression is a value and therefore cannot be the target of an assignment
================================================
======================================================
characterarray.replace (1Pos+1,KeyFirst)
Overload failed because no acceccible "Replace" accpets this number of arguments
====================================================
Last edited by angelica; Apr 15th, 2009 at 07:20 AM.
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Apr 15th, 2009, 07:36 AM
#6
Re: Syntax error in string manipulation
I'm confused.
Arrays don't have a Substring or Replace method and so you should get errors like :
'Replace' is not a member of 'System.Array'
If characterarray was a string it would make more sense.
The first error you are getting would be because you cant assign values to the result of a "substring" function - it is only for reading parts of a string, not for setting parts of it.
Last edited by keystone_paul; Apr 15th, 2009 at 07:40 AM.
-
Apr 15th, 2009, 07:43 AM
#7
Re: Syntax error in string manipulation
Hey,
I would agree with Paul on this one.
The methods that you are trying to use do not exist on that Type. Are you perhaps trying to index into the array?
I might help by explaining exactly what you are trying to achieve.
Gary
-
Apr 15th, 2009, 07:56 AM
#8
Thread Starter
Frenzied Member
Re: Syntax error in string manipulation
What I am trying to do is this:
I have a user input which is : Dim encodestring As String = txtmessage.Text
and Im trying to insert it by replacing strings in the characterarray which is a randomgenerator declared in the
Code:
Sub Main:
Dim characterarray() As Char
characterarray = RandomGen1.ToCharArray()
Now I get an integer IUseGap which is an integer which will serve as the character spaces between the number of characters in between each letterof encodestring.
Then I get a KeyGap (integer converted to Ascii) and KeyFirst (converted dto ascii which will be the end of the insertion.
I have to do these replacing .
Let me give you an example
encodestring = HEY
and should be inserted in randomGen1 = abcdefgvvvvvvvvvvvhijkoo
so the IuseGap would be 4 ( distance between i and length)
and first would be "H"
so for example I need to do abHdefgEvvvvY4Hvvvvvhijkoo
Hope I made it a bit less complicated!
Last edited by angelica; Apr 15th, 2009 at 08:32 AM.
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Apr 15th, 2009, 08:00 AM
#9
Re: Syntax error in string manipulation
Hope I made it a bit less complicated!
Well I don't know about gep13 but it just makes my head hurt
The fact remains that you appear to be trying to call string methods on an array, which won't work.
-
Apr 15th, 2009, 08:05 AM
#10
Re: Syntax error in string manipulation
Hey,
I am going to have to give this one some more thought when I am not at work.
What you are requesting is possible, but it will take some work.
My question would be though, are you trying to copy some pre-existing code? Intellisense in the IDE would have told you that those methods don't exist.
For the members that are available, have a look here:
http://msdn.microsoft.com/en-us/libr...y_members.aspx
Gary
-
Apr 15th, 2009, 08:07 AM
#11
Re: Syntax error in string manipulation
two things....
1) Replace takes two CHARACTER or STRING parameters.... and it RETURNS a string with the replaced bits.... so to use it to replace things use it like this: strMyString = strMyString.Replace("find this","Replace with")
2) characterarray.replace (1Pos+1,KeyFirst) -- I'm hoping it's just a typo but to the best of my knowledge... you can't have variables start with a number (that's a 1 (one) not an l (lower case L)) ... even if you can... 1Pos and lPos aren't the same thing... even if they look similar. 
-tg
-
Apr 15th, 2009, 08:27 AM
#12
Thread Starter
Frenzied Member
Re: Syntax error in string manipulation
Thanks guys,
Techgnome I corrected the 1Pos and replace but Im still stuck. My latest version stand like this:
The charAt are no VB.Net syntax but Im at a loss which to use 
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsecrettMessage.Click
'Splitletters()
Dim KeyFirst, KeyGap, secretmessage As String
Dim encodestring As String = txtmessage.Text
lStartAt = 200 + lUse5th
Dim Pos1 As Long
Dim Pos2 As Long
KeyFirst = Asc(encodestring(0))
KeyGap = (Asc(lUseGap))
encodestring += String.Format(KeyFirst + KeyGap)
For Pos1 = 1 To encodestring.Length
characterarray.charAT((Pos1 - 1) * lUseGap + lStartAt) = encodestring.charAT(Pos1 - 1)
If (encodestring.Length - 2 = True) Then
characterarray = characterarray.Replace(Pos1 + 1, KeyFirst)
End If
If (encodestring.Length - 1 = True) Then
characterarray = (characterarray.Replace(Pos1 + 2, KeyGap))
End If
Next
secretmessage = characterarray.ToString
End Sub
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|