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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How pass a variable inside a function to other function?

Status
Not open for further replies.

Gti

Programmer
Jul 23, 2001
99
PT
Public Sub ScanFonteFicheiro(Ficheiro As String, DirDestino As String)

Dim fichsaida As String

ConstroiNomeSaida(Ficheiro, DirDestino)

Exit Sub
End Sub

---------------

Public Sub ConstroiNomeSaida(Ficheiro As String, DisDestino As String)

Dim NomeFichTmp, NomeFichHtm, DirHtm As String
Dim TotalChar, TiraExtensao As Integer

TotalChar = Len(Ficheiro)
TiraExtensao = TotalChar - 3
NomeFichTmp = Left(Ficheiro, TiraExtensao)
NomeFichHtm = NomeFichTmp & "htm"
DirHtm = DisDestino & "\" & NomeFichHtm

Exit Sub
End Sub

---------------------------------------------------------

What i want to pass is the DirHtm variable for the first function... How can i do this?
 
Change your ConstroiNomeSaida procedure to be a function (then you can return the value you require)


Public Sub ScanFonteFicheiro(Ficheiro As String, DirDestino As String)

Dim fichsaida As String

Dim strReturn As String

strReturn = ConstroiNomeSaida(Ficheiro, DirDestino)

Exit Sub
End Sub

---------------

Public Function ConstroiNomeSaida(Ficheiro As String, DisDestino As String) as String

Dim NomeFichTmp, NomeFichHtm, DirHtm As String
Dim TotalChar, TiraExtensao As Integer

TotalChar = Len(Ficheiro)
TiraExtensao = TotalChar - 3
NomeFichTmp = Left(Ficheiro, TiraExtensao)
NomeFichHtm = NomeFichTmp & "htm"
DirHtm = DisDestino & "\" & NomeFichHtm

ConstroiNomeSaida = DirHtm

Exit Function
End Function

Cheers

Madlarry
 
This is just the first thing that came to me:

Code:
DirHtm = DisDestino & "\" & NomeFichHtm 'under this line try
Call ScanFonteFicheiro(NomeFichHtm , DirHtm) 'again! :o)


bluenote@uyuyuy.com
(excuse my english)
 
It gives me an error of "Expected function or variable"...

What happened? I have done everything like you said!
 
Which line gives you the error???

Also, the following line:

Dim NomeFichTmp, NomeFichHtm, DirHtm As String

Will only delare DirHtm as a string, the other two variables NomeFichTmp and NomeFichHtm will be variants. You may want to declare them on separate lines:

Dim NomeFichTmp as String
Dim NomeFichHtm as String
Dim DirHtm as String

Cheers,

Madlarry
 
I agree with Madlarry 'bout declarations.

Code:
Public Sub ScanFonteFicheiro(Ficheiro As String, DirDestino As String)

 Dim fichsaida As String

 fichsaida = ConstroiNomeSaida(Ficheiro, DirDestino)

End Sub

---------------

Public Function ConstroiNomeSaida(Ficheiro As String, DisDestino As String) as string

 Dim NomeFichTmp as string
 dim NomeFichHtm as string
 dim DirHtm      As String
 Dim TotalChar   as integer
 dim TiraExtensao As Integer

 TotalChar = Len(Ficheiro)
 TiraExtensao = TotalChar - 3
 NomeFichTmp = Left(Ficheiro, TiraExtensao)
 NomeFichHtm = NomeFichTmp & "htm"
 DirHtm = DisDestino & "\" & NomeFichHtm

 ConstroiNomeSaida = DirHtm

End Function

---------------------------------------------------------

:eek:) bluenote@uyuyuy.com
(excuse my english)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top