Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6872185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:53:46+00:00 2026-05-27T03:53:46+00:00

This is my first time working with VB. I’m mostly used to working in

  • 0

This is my first time working with VB. I’m mostly used to working in matlab and am finding that a lot of what I take for granted in matlab must be explicitly declared in VB. Frustrating!

In particular I need to declare two array sizes s1 and s2. As you can see in the code below, s1 is the number of elements in set “n” where the variable “stratum” equals 1. s2 is the number of elements in set “n” where the variable “stratum” equals 2. Pretty straightforward.

My approach is simply to loop the stratum variable 1 through n and count these occurences; and then declare the resulting sums as constants. This would work swimmingly in matlab, but VB is not accepting s1 and s2 as constants. It won’t even display s1 and s2 when I insert a debug.print command after the loop.

I have looked through the relevant posts already made. I appreciate any advice. Thanks.

    Sub TOAinput()

    Const n As Integer = 648

    Dim stratum(n), hybrid(n), acres(n), hhsz(n), offinc(n)

    For i = 1 To n
        stratum(i) = Worksheets("hhid level").Cells(i + 1, 2).Value
    Next i

    Dim s1 As Integer
    Dim s2 As Integer


    s1 = 0
    s2 = 0
    For i = 1 To n
        If stratum(i) = 1 Then
            s1 = s1 + 1
        Else:
            s2 = s2 + 1
        End If
    Next i

    Dim acres1(s1), hhsz1(s1), offinc1(s1), acres2(s2), hhsz2(s2), offinc2(s2)

    (...)
    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:53:46+00:00Added an answer on May 27, 2026 at 3:53 am

    This should work slightly better for you:

    Sub TOAinput()
    
    Const n As Integer = 648
    
    Dim stratum(n) As Integer
    Dim hybrid(n) As Integer
    Dim acres(n) As Integer
    Dim hhsz(n) As Integer
    Dim offinc(n) As Integer
    
    Dim i As Integer
    
    For i = 1 To n
        stratum(i) = Worksheets("hhid level").Cells(i + 1, 2).Value
    Next
    
    Dim s1 As Integer
    Dim s2 As Integer
    
    For i = 1 To n
        If stratum(i) = 1 Then
            s1 = s1 + 1
        Else
            s2 = s2 + 1
        End If
    Next
    
    Dim acres1() As Integer
    Dim hhsz1() As Integer
    Dim offinc1() As Integer
    Dim acres2() As Integer
    Dim hhsz2() As Integer
    Dim offinc2() As Integer
    
    ReDim acres1(s1)
    ReDim hhsz1(s1)
    ReDim offinc1(s1)
    ReDim acres2(s2)
    ReDim hhsz2(s2)
    ReDim offinc2(s2)
    
    (...)
    End Sub
    

    I would also recommend that, if possible, you declare the types on the arrays. I have assumed that they are all ints and modified the code appropriately, but this may not work in your situation (i.e. different data types).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on an ASP.NET MVC2 project. This is the first time
This is my first time truly working with composite keys. I have a record
This is my first time working with a webservice and I tried looking up
This question arises out of a combination of this being my first time working
This is my first time working with python. I'm trying to create a dictionary
This is my first time working with windows service, and I am learning as
So here I have this first time app I'm working on. When I run
So I'm working on an app in Django, however this is my first time
This is my first time working on php code. I've put some printf code
This is my first time working with localStorage, and I'm trying to store a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.