Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Passing a string aray as an argument to a function ?....Help!

I am trying to pass a string array as an argument for a function, but I keep
getting this compile error,

Type mismatch: array or user-defined type expected

Here is my code, why won't this work ?

Option Explicit
Option Base 1
Dim Oil(18), Gas(18), HO(18) As String

Sub SetChrtPosAndColor()
GetChartNumsFromTxtFile
WriteChartNums2txtFile Oil
End Sub

Function GetChartNumsFromTxtFile()
Dim X As Integer
Open "C:\ChrtNumLst.txt" For Input As #1
For X = 1 To 54
If X < 19 Then
Line Input #1, Oil(X)
ElseIf X 18 And X < 37 Then
Line Input #1, Gas(X - 18)
ElseIf X 36 Then
Line Input #1, HO(X - 36)
End If
Next X
Close #1
End Function

Function WriteChartNums2txtFile(Commodity() As String)
Dim X As Integer
Open "C:\WriteChtNum.txt" For Output As #1
For X = 1 To 18
Print #1, Commodity(X)
Next X
Close #1
End Function


Dan Thompson.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Passing a string aray as an argument to a function ?....Help!

Hi Dan,

Don't know much about this. What I do know, however, is that the "As String"
declaration only works for the last defined name. So you should use

Dim Oil(18) As String, Gas(18) As String, HO(18) As String

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"Dan Thompson" wrote in message
...
I am trying to pass a string array as an argument for a function, but I
keep
getting this compile error,

Type mismatch: array or user-defined type expected

Here is my code, why won't this work ?

Option Explicit
Option Base 1
Dim Oil(18), Gas(18), HO(18) As String

Sub SetChrtPosAndColor()
GetChartNumsFromTxtFile
WriteChartNums2txtFile Oil
End Sub

Function GetChartNumsFromTxtFile()
Dim X As Integer
Open "C:\ChrtNumLst.txt" For Input As #1
For X = 1 To 54
If X < 19 Then
Line Input #1, Oil(X)
ElseIf X 18 And X < 37 Then
Line Input #1, Gas(X - 18)
ElseIf X 36 Then
Line Input #1, HO(X - 36)
End If
Next X
Close #1
End Function

Function WriteChartNums2txtFile(Commodity() As String)
Dim X As Integer
Open "C:\WriteChtNum.txt" For Output As #1
For X = 1 To 18
Print #1, Commodity(X)
Next X
Close #1
End Function


Dan Thompson.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Passing a string aray as an argument to a function ?....Help!

A couple of problems...
One your declaration does not work. Try this

Private Oil(18) As String
Private Gas(18) As String
Private HO(18) As String

The other problem (not that it will keep the project from compiling) is that
your functions should be changed to sub procedures. A function returns a
value. Your functions do not return values.

"Niek Otten" wrote:

Hi Dan,

Don't know much about this. What I do know, however, is that the "As String"
declaration only works for the last defined name. So you should use

Dim Oil(18) As String, Gas(18) As String, HO(18) As String

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"Dan Thompson" wrote in message
...
I am trying to pass a string array as an argument for a function, but I
keep
getting this compile error,

Type mismatch: array or user-defined type expected

Here is my code, why won't this work ?

Option Explicit
Option Base 1
Dim Oil(18), Gas(18), HO(18) As String

Sub SetChrtPosAndColor()
GetChartNumsFromTxtFile
WriteChartNums2txtFile Oil
End Sub

Function GetChartNumsFromTxtFile()
Dim X As Integer
Open "C:\ChrtNumLst.txt" For Input As #1
For X = 1 To 54
If X < 19 Then
Line Input #1, Oil(X)
ElseIf X 18 And X < 37 Then
Line Input #1, Gas(X - 18)
ElseIf X 36 Then
Line Input #1, HO(X - 36)
End If
Next X
Close #1
End Function

Function WriteChartNums2txtFile(Commodity() As String)
Dim X As Integer
Open "C:\WriteChtNum.txt" For Output As #1
For X = 1 To 18
Print #1, Commodity(X)
Next X
Close #1
End Function


Dan Thompson.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Passing a string aray as an argument to a function ?....Help!

Thanks Jim and Niek changing the array declarations worked!

Multi Declarations on a single line.
So would This Declaration only assign string type to "Z" then ?

Dim X, Y, Z As String

Dan.



"Jim Thomlinson" wrote:

A couple of problems...
One your declaration does not work. Try this

Private Oil(18) As String
Private Gas(18) As String
Private HO(18) As String

The other problem (not that it will keep the project from compiling) is that
your functions should be changed to sub procedures. A function returns a
value. Your functions do not return values.

"Niek Otten" wrote:

Hi Dan,

Don't know much about this. What I do know, however, is that the "As String"
declaration only works for the last defined name. So you should use

Dim Oil(18) As String, Gas(18) As String, HO(18) As String

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"Dan Thompson" wrote in message
...
I am trying to pass a string array as an argument for a function, but I
keep
getting this compile error,

Type mismatch: array or user-defined type expected

Here is my code, why won't this work ?

Option Explicit
Option Base 1
Dim Oil(18), Gas(18), HO(18) As String

Sub SetChrtPosAndColor()
GetChartNumsFromTxtFile
WriteChartNums2txtFile Oil
End Sub

Function GetChartNumsFromTxtFile()
Dim X As Integer
Open "C:\ChrtNumLst.txt" For Input As #1
For X = 1 To 54
If X < 19 Then
Line Input #1, Oil(X)
ElseIf X 18 And X < 37 Then
Line Input #1, Gas(X - 18)
ElseIf X 36 Then
Line Input #1, HO(X - 36)
End If
Next X
Close #1
End Function

Function WriteChartNums2txtFile(Commodity() As String)
Dim X As Integer
Open "C:\WriteChtNum.txt" For Output As #1
For X = 1 To 18
Print #1, Commodity(X)
Next X
Close #1
End Function


Dan Thompson.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Passing a string aray as an argument to a function ?....Help!

This Declaration only assign string type to "Z" then ?

Dim X, Y, Z As String


Yes. "Dim X, Y, Z As String" amounts to declaring X and Y as Variants and Z
as a String.

"Dan Thompson" wrote in message
...
Thanks Jim and Niek changing the array declarations worked!

Multi Declarations on a single line.
So would This Declaration only assign string type to "Z" then ?

Dim X, Y, Z As String

Dan.



"Jim Thomlinson" wrote:

A couple of problems...
One your declaration does not work. Try this

Private Oil(18) As String
Private Gas(18) As String
Private HO(18) As String

The other problem (not that it will keep the project from compiling) is

that
your functions should be changed to sub procedures. A function returns a
value. Your functions do not return values.

"Niek Otten" wrote:

Hi Dan,

Don't know much about this. What I do know, however, is that the "As

String"
declaration only works for the last defined name. So you should use

Dim Oil(18) As String, Gas(18) As String, HO(18) As String

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"Dan Thompson" wrote in

message
...
I am trying to pass a string array as an argument for a function, but

I
keep
getting this compile error,

Type mismatch: array or user-defined type expected

Here is my code, why won't this work ?

Option Explicit
Option Base 1
Dim Oil(18), Gas(18), HO(18) As String

Sub SetChrtPosAndColor()
GetChartNumsFromTxtFile
WriteChartNums2txtFile Oil
End Sub

Function GetChartNumsFromTxtFile()
Dim X As Integer
Open "C:\ChrtNumLst.txt" For Input As #1
For X = 1 To 54
If X < 19 Then
Line Input #1, Oil(X)
ElseIf X 18 And X < 37 Then
Line Input #1, Gas(X - 18)
ElseIf X 36 Then
Line Input #1, HO(X - 36)
End If
Next X
Close #1
End Function

Function WriteChartNums2txtFile(Commodity() As String)
Dim X As Integer
Open "C:\WriteChtNum.txt" For Output As #1
For X = 1 To 18
Print #1, Commodity(X)
Next X
Close #1
End Function


Dan Thompson.







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Passing a string aray as an argument to a function ?....Help!

Only Z would be a variable of type string. X and Y would be variants.

--
Regards,
Tom Ogilvy

"Dan Thompson" wrote in message
...
Thanks Jim and Niek changing the array declarations worked!

Multi Declarations on a single line.
So would This Declaration only assign string type to "Z" then ?

Dim X, Y, Z As String

Dan.



"Jim Thomlinson" wrote:

A couple of problems...
One your declaration does not work. Try this

Private Oil(18) As String
Private Gas(18) As String
Private HO(18) As String

The other problem (not that it will keep the project from compiling) is

that
your functions should be changed to sub procedures. A function returns a
value. Your functions do not return values.

"Niek Otten" wrote:

Hi Dan,

Don't know much about this. What I do know, however, is that the "As

String"
declaration only works for the last defined name. So you should use

Dim Oil(18) As String, Gas(18) As String, HO(18) As String

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel


"Dan Thompson" wrote in

message
...
I am trying to pass a string array as an argument for a function, but

I
keep
getting this compile error,

Type mismatch: array or user-defined type expected

Here is my code, why won't this work ?

Option Explicit
Option Base 1
Dim Oil(18), Gas(18), HO(18) As String

Sub SetChrtPosAndColor()
GetChartNumsFromTxtFile
WriteChartNums2txtFile Oil
End Sub

Function GetChartNumsFromTxtFile()
Dim X As Integer
Open "C:\ChrtNumLst.txt" For Input As #1
For X = 1 To 54
If X < 19 Then
Line Input #1, Oil(X)
ElseIf X 18 And X < 37 Then
Line Input #1, Gas(X - 18)
ElseIf X 36 Then
Line Input #1, HO(X - 36)
End If
Next X
Close #1
End Function

Function WriteChartNums2txtFile(Commodity() As String)
Dim X As Integer
Open "C:\WriteChtNum.txt" For Output As #1
For X = 1 To 18
Print #1, Commodity(X)
Next X
Close #1
End Function


Dan Thompson.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a range name as an argument to the Index Function Michael Sharpe Excel Discussion (Misc queries) 3 September 5th 12 01:33 PM
Passing range as an argument in a function Hari[_3_] Excel Programming 1 June 15th 04 02:41 AM
VBA - Passing a FUNCTION as an Argument James B Excel Programming 3 February 18th 04 03:42 PM
Passing an Array of User-Defined Type to an Argument of a Function Tushar Mehta[_6_] Excel Programming 0 August 17th 03 06:43 PM
passing a variable as an argument to a function Drew[_6_] Excel Programming 3 July 25th 03 08:51 PM


All times are GMT +1. The time now is 02:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"