• 0

Visual Basic - Making 1000 = "*"


Question

Need help making every 1000 = "*"

attach is what the final result should look like
This is my code:

Public Class Form1
 
    Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnShow.Click
 
        'Number of planets before Pluto was "let go"'
        Const intNUM_PLANETS As Integer = 9
 
        'Planet names'
        Dim strArrayPlanetNames() As String =
        {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}
 
        'diameter of each planet in miles'
        Dim dblArrayPlanetSizes() As Double =
        {3031, 7521, 7926, 4223, 88846, 74898, 31763, 30800, 1430}
 
 
        For intX = 0 To intNUM_PLANETS - 1
 
            'output name and size'
            lstPlanets.Items.Add(strArrayPlanetNames(intX) & "      " & dblArrayPlanetSizes(intX))
 
            'output bar chart on next line'
        Next
        
    End Sub

post-503111-0-56641300-1376880908.png

Link to comment
https://www.neowin.net/forum/topic/1171589-visual-basic-making-1000/
Share on other sites

15 answers to this question

Recommended Posts

  • 0

ermm is it something like this? this does not work but like what code should i add inside the lstPlanets.items.add(.....)

Option Strict On
Option Explicit On
'Anthony L
'CS 115
'Summer 2013
 Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnShow.Click
 
        'Number of planets before Pluto was "let go"'
        Const intNUM_PLANETS As Integer = 9
 
        'Planet names'
        Dim strArrayPlanetNames() As String =
        {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}
 
        'diameter of each planet in miles'
        Dim dblArrayPlanetSizes() As Double =
        {3031, 7521, 7926, 4223, 88846, 74898, 31763, 30800, 1430}
        Dim stars = New String("*"c, 1) 'stars = "*****"
 
        For intX = 0 To intNUM_PLANETS - 1
 
            'output name and size'
            lstPlanets.Items.Add(strArrayPlanetNames(intX) & "      " & dblArrayPlanetSizes(intX))
            lstPlanets.Items.Add(stars)
        Next
 
 
    End Sub
  • 0

Note: psuedo code below:

Const intNUM_PLANETS As Integer = 9

Dim strArrayPlanetNames() As String =
   {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"}
Dim dblArrayPlanetSizes() As Double =
   {3031, 7521, 7926, 4223, 88846, 74898, 31763, 30800, 1430}
 
For intX = 0 To intNUM_PLANETS - 1
   lstPlanets.Items.Add(strArrayPlanetNames(intX) & "      " & dblArrayPlanetSizes(intX))
  
   Dim numberOfStars As ??? = dblArrayPlanetSizes(intX))/1000   //??? - select variable type without decimal places
   for intY = 0 To numberOfStars
      lstPlanets.Items.Add("*")
   Next

Next
  • 0
Take the time to think about your problem, the data you have and in which form it is available. There's no point trying to get code examples to paste into your assignment if you don't understand how to reason about solving your problem. The code I gave you was not meant to be pasted verbatim into your assignment, but simply to illustrate how to create a string containing a repeating character.

 

Here's your problem in words:

For every planet you need to print its name and a certain amount of stars that corresponds to its size divided by 1000 and rounded up.

 

The planet names are in the array strArrayPlanetNames. The sizes are in the array dblArrayPlanetSizes.

 

For each planet, you'll first need to get its name and size from these arrays. Printing the name is easy. Printing the stars consists in

  1. finding the number of stars to print (i.e. the size divided by 1000 and rounded up)
  2. creating a string containing that many stars (I've showed you how already)
  3. printing that string to the output
 

From there it's only a matter of language syntax. Do you not understand what is an array, or how to get an element from an array? Or how to perform a division? Do you not understand what a for loop is? It's not clear where exactly lies the source of your confusion.

  • Like 1
  • 0

The best way to learn is by troubleshooting. Come up with a flowchart first, then write pseudo code for each block. This will makes things a lot clearer when writing code (at first).

 

If you just copy someone else's code, you will forget it after a few minutes.

  • 0

Yeah that's true but i do not learn a lot since this is an online class and the teacher never teach us or told us to read page something so i always google and read by myself which is kinda hard for me and there are several things that i have not learn maybe? or not? and yes it's very hard for me to know these codes... and btw 68k i tried using your code but then it multiply a lot of times and i do not really get the term of IntY = 0 so do we like start from the first number or?

this is what i have so far:

For intX = 0 To intNUM_PLANETS - 1
 
                'output name and size'
                lstPlanets.Items.Add(strArrayPlanetNames(intX) & "      " & dblArrayPlanetSizes(intX))
            Dim numberOfStars As Double = dblArrayPlanetSizes(CInt((intX) / 1000))
            For intY = 0 To numberOfStars
                lstPlanets.Items.Add("*")
            Next
 
        Next
  • 0

Yeah that's true but i do not learn a lot since this is an online class and the teacher never teach us or told us to read page something so i always google and read by myself which is kinda hard for me and there are several things that i have not learn maybe? or not? and yes it's very hard for me to know these codes... and btw 68k i tried using your code but then it multiply a lot of times and i do not really get the term of IntY = 0 so do we like start from the first number or?

this is what i have so far:

For intX = 0 To intNUM_PLANETS - 1

 

                'output name and size'

                lstPlanets.Items.Add(strArrayPlanetNames(intX) & "      " & dblArrayPlanetSizes(intX))

            Dim numberOfStars As Double = dblArrayPlanetSizes(CInt((intX) / 1000))

            For intY = 0 To numberOfStars

                lstPlanets.Items.Add("*")

            Next

 

        Next

What is CInt((intX) / 1000) supposed to be? It's the array index divided by 1000 and converted to an integer - which it already is. The value of this expression will always be 0. This doesn't make sense. You're not thinking about what your values represent.

 

Then you create a variable named numberOfStars which you assign to one of the values of dblArrayPlanetSizes array. This doesn't make sense: this array contains planet sizes. If you take an element from it, this element is a planet size, not a number of stars.

 

Also, you don't want to add each star as a separate list item; this will add each star on its own line. Create the string as I showed you and then add it as a single item to the list.

 

You want to 1) get the planet size from the array, 2) divide that size by 1000; 3) use the result of that division as the number of stars to create your string.

 

That's three sub-problems to solve. You know how to solve each of these individually; every one is just a single basic of code. Here are some hints (replace the comments with your code):

 

Dim planetSize = '... get the size from the array'
Dim numberOfStars = '... divide that size by 1000 and round up'
Dim stars = New String("*"C,  '... use the calculated number of stars to specify how many stars to put'
lstPlanet.Items.Add('... add that string the output'

By the way please use code tags when you post code.

  • 0

+Asik

I manage to get it working but is there another way to round this up?

 
               lstPlanets.Items.Add(strArrayPlanetNames(intX) & "      " & dblArrayPlanetSizes(intX))
            Dim numberOfStars As Double = Math.Round(dblArrayPlanetSizes(intX) / 1000) '... divide that size by 1000 and round up'
            Dim stars = New String("*"c, CInt(numberOfStars))  '... use the calculated number of stars to specify how many stars to put'
            lstPlanets.Items.Add(stars + "*") '... add that string the output'
  • 0

... why would you create a new duplicate array containing the planet sizes? How could you then divide that array by 1000? That wouldn't even compile.

 

The snippet I gave you goes inside your for loop. Use the loop index variable to access the existing planet size array you have, and retrieve a single planet size at a time.

 

By the way, the code you post often doesn't even compile. If you're working inside an IDE like Visual Studio, you should see red squiggles under the problematic lines and errors listed below. You don't need people on a forum to tell you your code doesn't work when Visual Studio already tells you that. Always make sure your code compiles and runs before anything else.

  • 0

 

Yeah that's true but i do not learn a lot since this is an online class and the teacher never teach us or told us to read page something so i always google and read by myself which is kinda hard for me and there are several things that i have not learn maybe? or not? and yes it's very hard for me to know these codes... and btw 68k i tried using your code but then it multiply a lot of times and i do not really get the term of IntY = 0 so do we like start from the first number or?

this is what i have so far:

For intX = 0 To intNUM_PLANETS - 1
 
                'output name and size'
                lstPlanets.Items.Add(strArrayPlanetNames(intX) & "      " & dblArrayPlanetSizes(intX))
            Dim numberOfStars As Double = dblArrayPlanetSizes(CInt((intX) / 1000))
            For intY = 0 To numberOfStars
                lstPlanets.Items.Add("*")
            Next
 
        Next

 

From http://msdn.microsoft.com/en-us/library/vstudio/5z06z1kb.aspx:

 

You use a For...Next structure when you want to repeat a set of statements a set number of times.

In the following example, the index variable starts with a value of 1 and is incremented with each iteration of the loop, ending after the value of index reaches 5.

For index As Integer = 1 To 5
    Debug.Write(index.ToString & " ")
Next
Debug.WriteLine("")
' Output: 1 2 3 4 5

Every time the For loop is initiated the variable "index" would be reset to "1".

  • 0

i tried it and it work well :|

Why are you surprised? IMO the method you're following doesn't seem to teach you the fundamentals right; you don't really understand what you're doing and just rushing through exercices. You'll hit a wall pretty soon at that rate. Get a good book and read it carefully. Learn to:

 

 - understand compiler error messages and how to find information about them

 - step through your code in the debugger so you can visualize what your program is doing at every statement

 

With good foundations you shouldn't need to ask people to guide you every step of the way, and then wonder how the program ended up working. Unfortunately, many courses are just plain bad, so you need to get additional resources by yourself. When I learned C++ I bought myself a huge tutorial book and read it on the bus; the material shown in class and exercices was insufficient by far.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Microsoft Teams is getting a controversial location tracking feature that users may hate by Usama Jawad Image generated with Microsoft Copilot Earlier this year, Microsoft planned to roll out a controversial location tracking feature in Teams, but following customer feedback, it decided to delay its release. The bad news is that the company has decided to launch it later this year, but it's based on roughly the same design that was shared earlier, which means that many users still have good reason to worry. Basically, Microsoft Places and Teams have received workplace check-ins via Wi-Fi. The idea is that if an employee arrives at the office and connects to their enterprise network, their profile status indicator will show them as being present in the office. For example, if you arrive at work, open Teams on your PC, and connect to the "Studio B" company Wi-Fi network, your Teams profile will indicate that you are present in "Studio B", as shown below: Microsoft says that this feature is basically a replacement for physical workplace check-in peripherals, it reduces the need to manually update your status, and it also enables co-workers to know that you're at work so that they can coordinate in-person meetings with you. IT admins can enable this workplace check-in capability at a tenant level, and users have the ability to control whether they want to enable it or not. Of course, all of that sounds great on paper, but naturally, many Teams customers may still have concerns, as they did before. This is because it enables your reporting manager and other members of the organization to track if you are at the office, when you arrive at the office, and where you are right now. This could be problematic for people who work in what they consider to be flexible work environments or hybrid setups, and this kind of location tracking could be considered an invasion of privacy. Microsoft has tried to alleviate some of these concerns by letting users know that they can manually set their location easily, which essentially overrides workplace check-in if they feel uncomfortable with it. However, that doesn't really solve the problem because your organization could enforce a workplace policy that mandates that this feature remains enabled. The Redmond tech giant has also assured users that this capability does not store historical data and is only a real-time indicator of location. Finally, it only generates a signal when you connect to a corporate network, which means that if you are working from home and connect your PC to your personal Wi-Fi, it won't broadcast your location to your employer; you will simply be shown as "Remote". Microsoft has encouraged IT admins to prepare for this change and begin informing users so they know what to expect once it begins rolling out later this year.
    • Wow, Microsoft IS cooking lately... This only shows that they COULD improve, they just chose not to for whatever reasons. That obsession with AI was destroying them from the inside out.
    • BATorrent 4.1.0 by Razvan Serea BATorrent is a lightweight, open-source BitTorrent client built with modern C++ and Qt 6, offering a clean, fast, and privacy-focused alternative to traditional torrent apps. It supports magnet links, .torrent files, resume data, sequential downloading, per-file priorities, and even imports from qBittorrent. Power users benefit from integrated RSS auto-download with regex filtering, duplicate detection, and automatic tracker lists from Stremio. Streaming is seamless thanks to auto-detected players like VLC and IINA. BATorrent includes robust VPN tools—interface binding, auto-detection for WireGuard-based services like Mullvad and NordLynx, kill switch, proxy support, and IP filtering. A full WebUI enables remote control, while integrations with Plex, Jellyfin, and Emby automate library updates. With themes, speed scheduling, system-tray alerts, and cross-platform support for Windows, Linux, and macOS, BATorrent delivers a polished, high-performance torrenting experience. BATorrent features: Core .torrent file and magnet link support Resume data — picks up where you left off after restart Import torrents from qBittorrent Create .torrent files from any file or folder Sequential download mode Per-file priority control (skip, low, normal, high) Seed ratio limits with auto-pause DHT, PEX, UPnP, NAT-PMP RSS Auto-Download Subscribe to RSS feeds — automatically download new torrents as they appear Regex filters — match only what you want (e.g. 1080p|720p, S01E\d+) Per-feed settings — custom save path, check interval (5–1440 min), enable/disable Auto-download — matched items are downloaded automatically in the background Supports magnet links, .torrent URLs, and tags Tray notifications when items are auto-downloaded Duplicate detection — never downloads the same item twice Stremio Stremio Addon System pre-installed — works out of the box Auto tracker list from ngosang/trackerslist Streaming Play while downloading — stream video files before the download is complete Supports mp4, mkv, avi, mov, wmv, flv, webm, m4v, ts Auto-detects installed players (VLC, IINA, system default) VPN & Privacy Interface binding — lock torrent traffic to a specific network interface (e.g. tun0) Auto VPN detection — identifies VPN interfaces (tun, tap, WireGuard, Mullvad, NordLynx, ProtonVPN) Kill switch — automatically pauses all torrents if the VPN interface drops Auto-resume — resumes only the torrents paused by the kill switch when VPN reconnects Proxy support — SOCKS5 and HTTP proxy with optional authentication IP filtering — load P2P blocklists to block unwanted IP ranges Protocol encryption (enabled / forced / disabled) WebUI Remote management — control torrents from any browser at http://localhost:8080 REST API with JSON responses Add torrents via magnet link or .torrent upload Pause, resume, remove torrents remotely View peers and files per torrent Dark theme matching the desktop app HTTP Basic Auth with SHA-256 password hashing Configurable port and remote access (localhost vs 0.0.0.0) Interface 3 themes: Dark, Light, Midnight (bat/vampire aesthetic) Real-time speed graph Detailed panel with tabs: General, Peers, Files, Trackers Filter bar: search by name, filter by state (Active, Downloading, Seeding, Paused, Finished) Drag & drop .torrent files and magnet links Drag & drop reorder in torrent list System tray with notifications (download complete, kill switch events, RSS auto-downloads) Splash screen with bat animation Bilingual: English and Portuguese (BR), auto-detected from system locale Bandwidth Scheduler Alternative speed limits — set different download/upload limits on a schedule Time range — configure active hours (e.g. 01:00 to 07:00), supports overnight ranges Per-day control — choose which days of the week the schedule applies Automatically switches between normal and alternative speeds Media Server Integration Plex — automatically trigger library scan when a download completes Jellyfin / Emby — same automatic library refresh via API Configure server URL and authentication token/key in Settings System Cross-platform: Windows, Linux, macOS Auto-shutdown — automatically shut down PC when all downloads complete (60s cancellable countdown) Auto-update system (AppImage on Linux, installer on Windows, DMG on macOS) CLI arguments: pass .torrent files or magnet: URIs directly Keyboard shortcuts: Space to toggle pause, Ctrl+A to select all, Ctrl+O to open BATorrent 4.1.0 release notes: A community-driven release: everything here came straight from your reports and requests. It closes the remaining gaps with qBittorrent and fixes the Windows settings/tray/splash issues several of you hit. Fixed Settings now actually save. A whole class of preferences — speed limits (and the alternative limits), max active downloads, seed ratio, listen port, max connections, DHT/uTP/encryption, VPN interface, kill switch and proxy — weren't being persisted and reset to defaults on every launch. They now round-trip correctly. (Thanks to everyone who reported "the upload limit always goes back to 0".) Splash and tray toggles stick on Windows. Turning off the startup animation (or "close to tray") no longer reverts — the Windows registry stored these booleans as integers and the UI was misreading them. Close-to-tray hint. The first time the window hides to the tray you get a one-time notification, so the app doesn't look like it vanished (Windows 11 tucks new tray icons into the overflow). macOS Dock icon size. The icon filled its canvas edge-to-edge and rendered larger than neighbouring apps; it now uses the standard safe-area padding. Native file picker language. The "Torrent file / All files" filter in the open dialog follows the app language instead of being hard-coded. Added — qBittorrent parity Alternative speed limits toggle — a turtle button in the toolbar flips your throttled limits on/off instantly, independent of the scheduler. Follow system theme — switch light/dark automatically with the OS (Settings → Appearance). Pre-allocate disk space — reserve the full file size up front to reduce fragmentation (Settings → Downloads). Recheck data on add — optionally force a hash check when adding a torrent, so existing or partial files on disk are detected. Port status indicator — a 🔴 dot in the status bar shows whether your listen port looks reachable (UPnP/NAT-PMP + listen state; fully local, no external check). Add torrent from URL — File → Add torrent from URL (Ctrl+U) fetches a remote .torrent and routes it through the normal add dialog. Export .torrent — right-click a torrent → Export .torrent to save its metadata file. Already there (in case you missed it) Watch folder — auto-add .torrent files dropped into a monitored directory (Settings → Files). This release just surfaces it. Incomplete files already carry a .!bt suffix until they finish. Under the hood Regression tests for the settings-persistence and Windows boolean bugs. A new Qt Quick Test harness covering the startup splash and the design-system widgets. Download: BATorrent 4.1.0 | 37.5 MB (Open Source) Download: BATorrent Portable | 51.7 MB Links: BATorrent Website | Screenshot | Changelog Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Very Popular
      AndrewSteel earned a badge
      Very Popular
    • Veteran
      Taliseian went up a rank
      Veteran
    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Week One Done
      Timaximus earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      517
    2. 2
      +Edouard
      163
    3. 3
      PsYcHoKiLLa
      162
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      78
  • Tell a friend

    Love Neowin? Tell a friend!