[arrays] lists and arrays in VBA

I am extremely new at writing in VB.NET, and I did not even realise that there was a significant difference between VB.NET and VBA. I have been writing my application in Visual Studio, but I realised that I will need to port it over to VBA in Outlook, and there are some syntax issues that I need to deal with. I have already searched, but I cannot find any sort of definitive reference (like the msdn) for VBA or even VB6, which from what I hear is much closer to VBA than VB.NET.

I will include the relevant sections of code here. If anyone needs more context, please let me know--I can post the whole thing, it's not that long. I would like to keep this post as simple as possible, though.

Dim DateToday As String = String.Format("0:{yyyy/MM/dd}", DateTime.Now)
Dim Computers As New SortedList()
Dim disabledList As New List(Of String)
'\\ four additional lists
Dim compArray As Array

...

Computers.Add(ComputerName, ErrorState)

The new lists and sorted list give Expected: End of Statement at the parenthesis after List. The array gives Expected: identifier at Array. The string DateToday gives an expected end of statement at the equals sign. The attempt to add to the sorted list gives an Expected: =.

I have been working with VB.NET for maybe two or three days, and I have never worked with VBA or VB6 before, so I just do not have the experience required to know where to go from here. If any of you would be willing to help me out, I would really appreciate it!

This question is related to arrays vb.net list vba sortedlist

The answer is


You will have to change some of your data types but the basics of what you just posted could be converted to something similar to this given the data types I used may not be accurate.

Dim DateToday As String: DateToday = Format(Date, "yyyy/MM/dd")
Dim Computers As New Collection
Dim disabledList As New Collection
Dim compArray(1 To 1) As String

'Assign data to first item in array
compArray(1) = "asdf"

'Format = Item, Key
Computers.Add "ErrorState", "Computer Name"

'Prints "ErrorState"
Debug.Print Computers("Computer Name")

Collections cannot be sorted so if you need to sort data you will probably want to use an array.

Here is a link to the outlook developer reference. http://msdn.microsoft.com/en-us/library/office/ff866465%28v=office.14%29.aspx

Another great site to help you get started is http://www.cpearson.com/Excel/Topic.aspx

Moving everything over to VBA from VB.Net is not going to be simple since not all the data types are the same and you do not have the .Net framework. If you get stuck just post the code you're stuck converting and you will surely get some help!

Edit:

Sub ArrayExample()
    Dim subject As String
    Dim TestArray() As String
    Dim counter As Long

    subject = "Example"
    counter = Len(subject)

    ReDim TestArray(1 To counter) As String

    For counter = 1 To Len(subject)
        TestArray(counter) = Right(Left(subject, counter), 1)
    Next
End Sub

Examples related to arrays

PHP array value passes to next row Use NSInteger as array index How do I show a message in the foreach loop? Objects are not valid as a React child. If you meant to render a collection of children, use an array instead Iterating over arrays in Python 3 Best way to "push" into C# array Sort Array of object by object field in Angular 6 Checking for duplicate strings in JavaScript array what does numpy ndarray shape do? How to round a numpy array?

Examples related to vb.net

How to get parameter value for date/time column from empty MaskedTextBox HTTP 415 unsupported media type error when calling Web API 2 endpoint variable is not declared it may be inaccessible due to its protection level Differences Between vbLf, vbCrLf & vbCr Constants Simple working Example of json.net in VB.net How to open up a form from another form in VB.NET? Delete a row in DataGridView Control in VB.NET How to get cell value from DataGridView in VB.Net? Set default format of datetimepicker as dd-MM-yyyy How to configure SMTP settings in web.config

Examples related to list

Convert List to Pandas Dataframe Column Python find elements in one list that are not in the other Sorting a list with stream.sorted() in Java Python Loop: List Index Out of Range How to combine two lists in R How do I multiply each element in a list by a number? Save a list to a .txt file The most efficient way to remove first N elements in a list? TypeError: list indices must be integers or slices, not str Parse JSON String into List<string>

Examples related to vba

Copy filtered data to another sheet using VBA Better way to find last used row Check if a value is in an array or not with Excel VBA Creating an Array from a Range in VBA Excel: macro to export worksheet as CSV file without leaving my current Excel sheet VBA: Convert Text to Number What's the difference between "end" and "exit sub" in VBA? Rename Excel Sheet with VBA Macro Extract Data from PDF and Add to Worksheet Quicker way to get all unique values of a column in VBA?

Examples related to sortedlist

lists and arrays in VBA How to Sort Date in descending order From Arraylist Date in android? Get random sample from list while maintaining ordering of items? What's the difference between SortedList and SortedDictionary?