3 Replies - 6736 Views - Last Post: 29 November 2009 - 08:08 AM Rate Topic: -----

#1 drummer_sniper  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-August 09

how to convert String to array of characters

Post icon  Posted 29 November 2009 - 05:38 AM

hi.

can someone help me on how to convert string to char?

like my input is 0123456

then i like to make it into an array of characters

please help..

thanks and God bless
Is This A Good Question/Topic? 0
  • +

Replies To: how to convert String to array of characters

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: how to convert String to array of characters

Posted 29 November 2009 - 06:07 AM

hello :)

can you help us by giving us the errors you have. the code where you have the errors. here on D.I.C we have the politic that we will not do your home work, work projects etc. You must show us some effort. Post the code you have trouble with in tags like so:

:code:

ty for helping us helping you :)

use Len() and Mid() functions

good luck with your project :)

This post has been edited by NoBrain: 29 November 2009 - 06:07 AM

Was This Post Helpful? 0
  • +
  • -

#3 drummer_sniper  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-August 09

Re: how to convert String to array of characters

Posted 29 November 2009 - 07:01 AM

OH! i sorry sir i forgot.

this is my code. my proram accepts a 7 digit input then multiplies the even number indexes
so if input: 0123456
only index 0, 2, 4, 6 only then the rest will just be added.
so 0 1 2 3 4 5 6
* * * *
2 2 2 2
= = = =
0+1+4+3+8+5+12
(3)
then if there will be a number then is greater then 9. the sperate digits will be added like 12 = 1+2 so final is 3.
then add them all.

thats what my program should do.
here's my code:
Dim inp As String
Dim ans As Integer
ans = 0
inp = txt_id.Text
Dim charArray() As Char

charArray = CType(myString, Char())


For d = 1 To Len(inp)
	If d Mod 3 Then
		If Val(Mid$(inp, d, 1)) * 2 > 9 Then
			ans = ans + ((Val(Mid$(inp, d, 1)) * 2 \ 10) + (Val(Mid$(inp, d, 1)) * 2 Mod 10))
			
		Else
			ans = ans + (Val(Mid$(inp, d, 1)) * 2)
			
		End If
	Else
		ans = ans + Val(Mid$(inp, d, 1))
		
	End If
Next d
chkd = 10 - ans Mod 10
End Sub


Was This Post Helpful? 0
  • +
  • -

#4 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: how to convert String to array of characters

Posted 29 November 2009 - 08:08 AM

hi dude :)

i dont rly understand your code and what you want but if i must answer your first question it will be like that

Private Sub Command1_Click()
	Dim myCharArry() As String
	Dim i As Integer
	ReDim myCharArry(Len(Text1.Text) - 1)
	
	For i = 1 To Len(Text1.Text)
		myCharArry(i - 1) = Mid(Text1.Text, i, 1)
	Next i
		For i = 0 To UBound(myCharArry)
					 Debug.Print myCharArry(i)
		Next i

End Sub




where myCharArry() is my array of strings. we redim it so it can have as much items as your string lenght. Remember that the array counts from 0 to the len. of your string -1. for that reason we send i-1 as element of the array and "i" as begin in the mid() function. the debug.print will return you the whole elements your array have. try it in some other form and see how it work :)
good luck :)

This post has been edited by NoBrain: 29 November 2009 - 08:17 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1