Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing matrix from function/module 1

Status
Not open for further replies.

AtleOlsen

Programmer
Aug 7, 2003
9
DK
Hi!

I need to pass a matrix from one function/module to another.
How is this possible?? I've tried the following code by it only gives me an empty matrix on the other side, any suggestions????
The point of the code is to divide a sentence up into words and add these words into a matrix for later use.

THX in advance

Private Function fSentenceData(sSentence As String) As String
Dim mData(4) As String
Dim bSentenceEnd As Boolean
Dim iCounter As Integer
Dim iSeperatorIndex As Integer
Dim sWorkString As String
Dim sTempWord As String
Dim iStringLen As Integer

bSentenceEnd = False
sWorkString = sSentence

Do While bSentenceEnd = False
iStringLen = Len(sWorkString)
iSeperatorIndex = InStr(sWorkString, " ")
If (iSeperatorIndex <> 0) Then
sTempWord = Left(sWorkString, iSeperatorIndex)
sWorkString = Right(sWorkString, (iStringLen - iSeperatorIndex))
Else
sTempWord = sWorkString
bSentenceEnd = True
End If
mData(iCounter) = sTempWord
iCounter = iCounter + 1
Loop

fSentenceData = mData(iCounter)

End Function

Private Function fScreenData(sScreenSentence As String) As Boolean
Dim mScreenData(4) As String

mScreenData(4) = fSentenceData(sScreenSentence)
End Function



When every things go black, scream, change the fuse and start over!! ARRGH!!
Atle
 
Here's a modification of your code that should do the trick:
[tt]
Private Function fSentenceData(sSentence As String) As String()
Dim mData(4) As String
Dim bSentenceEnd As Boolean
Dim iCounter As Integer
Dim iSeperatorIndex As Integer
Dim sWorkString As String
Dim sTempWord As String
Dim iStringLen As Integer

bSentenceEnd = False
sWorkString = sSentence

Do While bSentenceEnd = False
iStringLen = Len(sWorkString)
iSeperatorIndex = InStr(sWorkString, &quot; &quot;)
If (iSeperatorIndex <> 0) Then
sTempWord = Left(sWorkString, iSeperatorIndex)
sWorkString = Right(sWorkString, (iStringLen - iSeperatorIndex))
Else
sTempWord = sWorkString
bSentenceEnd = True
End If
mData(iCounter) = sTempWord
iCounter = iCounter + 1
Loop

fSentenceData = mData

End Function
[/tt]
However, you might want to consider VB's Split function, which means you could rewrite your function as:
[tt]
Private Function fSentenceData(sSentence As String) As String()
fSentenceData = Split(sSentence, &quot; &quot;)
End Function
 
Thanks a lot for both code e.g,
The last one makes it all a lot easier, it works wonders for me.

Atle


When every things go black,
scream, change the fuse and
start over!!
ARRGH!!
 
AtleOlsen , This is a good example of what this forum is all about: Helping a person be more productive at work.
Not only you got a correction to your code, but also a second piece of code which cuts done the size (and amount of possible places for errors) by a big chunk.

Welcome to Tek-Tips!
Read Faq222-2244 thoroughly, and mark post's like this above as helpful by using the option below the post &quot;Mark this post as a helpful/expert post!&quot;.
Thank you and have enjoy Tek-Tips!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top