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 8889271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:13:14+00:00 2026-06-14T22:13:14+00:00

i have a sub that will try to get random foods in the database,

  • 0

i have a sub that will try to get random foods in the database, get the sum of these food’s calories and check if they wont exceed the required calories.

most of the time the sub worked, but sometimes this error appears.
this is my code. it is kinda long.

Private Sub lunchgenerate()

        Dim grams As Integer = DSgrams.Tables("grams").Rows(0).Item("grams")
        Dim grams1 As Integer = DSricegrams.Tables("ricegrams").Rows(0).Item("grams")
        Dim grams2 As Integer = DSgrams2.Tables("grams").Rows(0).Item("grams")

        Dim calorieval As Decimal = foodcalories * grams
        Dim calorieval1 As Decimal = ricecalories * grams1
        Dim calorieval2 As Decimal = foodcalories2 * grams2

        Dim carbval As Decimal = foodcarb * grams
        Dim carbval1 As Decimal = ricecarb * grams1
        Dim carbval2 As Decimal = foodcarb2 * grams2

        Dim proteinval As Decimal = foodprotein * grams
        Dim proteinval1 As Decimal = riceprotein * grams1
        Dim proteinval2 As Decimal = foodprotein2 * grams

        Dim fatval As Decimal = foodfat * grams
        Dim fatval1 As Decimal = ricefat * grams1
        Dim fatval2 As Decimal = foodfat2 * grams

        Dim caloriepercent As Decimal = usercalories * 0.5
        Dim mincalories As Decimal = caloriepercent - 300

        Dim proteinpercernt As Decimal = userprotein * 0.5
        Dim minprotein As Decimal = proteinpercernt - 20

        Dim counter As Integer = 0
        Dim counter1 As Integer = 0

        Dim foodcalorietotal As Decimal = calorieval + calorieval1 + calorieval2
        Dim foodproteintotal As Decimal = proteinval + proteinval1 + proteinval2
        Dim carbtotal As Decimal = carbval + carbval1 + carbval2
        Dim foodfattotal As Decimal = fatval + fatval1 + fatval2

        If foodcalorietotal < mincalories Or foodcalorietotal > caloriepercent Then
            counter = 0
        Else
            counter = 1
        End If

        If foodproteintotal < minprotein Or foodproteintotal > proteinpercernt Then
            counter1 = 0
        Else
            counter1 = 1
        End If

        If counter = 1 And counter1 = 1 Then
          'output to the form

        Else

                **lunchgenerate()**

            End If

        End If
End Sub

i think the error is when the lunchgenerate() sub is called again.

but just like what i said, most of the times it worked, but sometimes it freezes and then this error appears and then highlights the first line of my code which is

        Dim DAlunchcategory As New SqlDataAdapter(lunchquery, CN)
        Dim DSlunchcategory As New DataSet
        DAlunchcategory.Fill(DSlunchcategory, "category_id")
  • 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-06-14T22:13:15+00:00Added an answer on June 14, 2026 at 10:13 pm

    Stack Overflow error happens when there is no space on the stack (part of the process memory used for local variables, parameter values, function results and a few other little things).

    Often the code that produces this error does it by executing infinite recursion. If the code that you showed is complete lunchgenerate function, in the case when either counter or counter1 is not 1, lunchgenerate will be called again with exactly the same outcome, and again, and again, until it completely depletes space on the stack and exception is thrown. You need to have some escape logic to avoid it.

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

Sidebar

Related Questions

In a module i have a sub that create modalpopup and show result of
I have a sub query that returns one column, showing as GroupType, I then
I have a sub form that looks like a datasheet view. It returns prices
We have a sub-project 'commonUtils' that has many generic code-snippets used across the parent
I have just found a script we are using which has a sub that
I have a directory with multiple sub directories that contain .doc files. Example: C:\Users\tmedina\Documents\testenviroment\Released\500\test0.doc
I have a sub form in Access: The CopyNo is a combobox that lets
I have a ubuntu pc's in internal sub-network that I'm running mongo on them.
I have a folder C:\Scripts. In that folder I have 2 sub folders, Procedures
i have a file, filedata.mat, containing a 1x1 struct with sub-levels that contain data

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.