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

Arrays in VB .NET VS 2019

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
568
US
Colleagues,
I can't recall, neither find (in VS documentation), how to declare an empty public array in Main sub, and then ReDim it and fill out.
Here's the code:
Code:
Module ASCII_Text_Search_Main
Public glDevelop As Boolean = System.Diagnostics.Debugger.IsAttached
Public gsStartDir As String = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)).Replace("\bin\Debug", "\")
Public Dim gaFileTypes()

Dim frmASCII_Text_Search As Form

Private Sub Main()
FillExtArray()

frmASCII_Text_Search.Show()

End Sub

'====================================================================================================================================
Sub FillExtArray()
'====================================================================================================================================
' Purpose       : Fills out public array gaFileTypes.
' Description   : Fills out public array gaFileTypes with ASCII text-searchable file extension types.
' Side effects  : None.
' Notes         : 1. Application-specific.
'                 2. Complies with .NET Framework ver. 1.1 and higher.
' Author        : Ilya I. Rabyy
' Revisions     : by Ilya on 2022-01-25 – started 1st draft.
'====================================================================================================================================
ReDim gaFileTypes(15)
gaFileTypes(0) = "*.*"
gaFileTypes(1) = "*.txt"
gaFileTypes(2) = "*.doc"
gaFileTypes(3) = "*.xls"
gaFileTypes(4) = "*.csv"
gaFileTypes(5) = "*.epb"
'...
gaFileTypes(14) = "*.vbproj"
End Sub
'====================================================================================================================================
When I run it with F5, it throws the following error:
2022_01_25_15_56_ASCII_Txt_Src_F5_Run_ArrayIsNotRecognized_ultyoz.jpg

What am I doing wrong?
Please advise.

Regards,

Ilya
 

I think it needs to be initialized. Try:

Code:
Public Dim gaFileTypes() As String = New String() {}


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
>needs to be initialized

Yep - but, in theory, FillExtArray() does this and is called before frmASCII_Text_Search.Show (which in turn triggers frmASCII_Text_Search.Load) in Main - which suggests that actually the issue is that somehow frmASCII_Text_Search.Load is running before the array is populated (in which case initialising the array as suggested will simply mask the problem, and cause a different error to be generated)

Ilya, can you confirm your project's startup object is configured as Sub Main in module ASCII_Text_Search_Main?
 
StrongM: where is it that I can set the start-up module as Main in a WinForms application? There's only "Startup Form" choice...
2022_01_26_10_02_VB_AppTab_iwal0x.jpg


Regards,

Ilya
 
UnCheck "Enable application framework" checkbox and your Main sub should be available in Startup form.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Andrzejek: did that, changed startup module to ASCII_Text_Search_Main... and now, even though declared as Public, the form frmASCII_Text_Search is not recognized:
2022_01_26_10_59_ASCII_Text_Search_FomIsNotRecognized_abti3c.jpg


Regards,

Ilya
 
So, you have a variable[tt]
Public Dim [blue]frmASCII_Text_Search[/blue] As Form[/tt]
and a Form in your application also named [blue]frmASCII_Text_Search[/blue] [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Delete the declaration for frmASCII_Text_Search - not needed for your program as it stands.
 
> So, you have a variable ... and a Form in your application

Sort of. He has a declaration of a variable that is intended to hold a reference to a class instance of the built-in class called Form, and thus will end up with an object called frmASCII_Text_Search that is an instance of Form.

And a reference to a self-instantiating class called frmASCII_Text_Search, which automatically creates a object also called frmASCII_Text_Search if any frmASCII_Text_Search class method or property is used.

Clear as mud, 'eh?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top