Home ยป VB Code explanation? [closed]

VB Code explanation? [closed]

Solutons:


Declare a student name variable that we will call studentname as a string. Think of variables as you would do x and y in an algebraic equation. They are simply names for things of a particular type. In a maths equation x and y are numbers. A string is a basically a sequence of characters, such as words, numbers, or any other arbitrary data. "Moo-Juice" is a string, for example – delimited by the " characters.

Declare a message called intMsg as a string.

Subroutine “Command1_Click”, called when the button (presumably) Command1 is clicked by the user. Subroutines are functions and are where you either put common code that you wish to re-use, or in the case of languages such as this, to respond to events that have occurred. Events in GUI applications come in various different flavours, this one is called when the user clicks a button. Others include MouseMove, KeyUp, KeyDown. Responding to these events allows your code to do stuff.

Set the Text1 control’s Text property to an empty string (clear it). Controls on a form (both the text box and the button are examples of controls), have properties. The Text property is where a Textbox control stores what you can see in the textbox. Controls generally have a whole bunch of properties. Left denotes where it is on the form with regards to the horizontal position. Font specifies want font to use, etc, etc. There are many different GUI systems, and beyond VB6 and in the .NET environment there are Windows Forms, and WPF (Windows Presentation Foundation). In other languages there are as many GUI systems as you can care to think of.

Declare variable1 as a string.

Within this subroutine (Command1_Click), should an error occur go to the file_error label that appears not to be in your code snippet so we can assume it is farther down, beyond the loop. GoTo does exactly what it says on the tin – it jumps to the label specified and execution continues there. On Error tells visual basic what to do if an error occurs, and in this case it is saying “Go there if something goes awry”.

Open the file specified, in read mode, assigning it file handle #1 for future reference. File handlers, like variables, are a way of identifying a file we want to do something with. Without file handlers (in VB6) if I open multiple files at the same time, how does the system know which one I want to write to? By saying “Open this file, and I’ll refer to it as #1“, we can tell the system which file we want to play with at any particular point in time.

Begin a loop. There are many loop constructs, and the verbosity of VB6 (and BASIC in general) allows you to see what kind of loop you’re doing. This is a Do loop. It will execute at least once, with the condition at the end being checked each iteration. Should that check return true, the loop stops. Other loop types include For (for fine-grained control over steps, and how many iteration. Other languages allow more expressive boolean logic to determine the exact lifetime of a for-loop), and While which is similar to do, but the check is performed at the top, so it may run zero times if the condition fails immediately.

Read in a line from file handle #1 in to our string variable variable1. Remember we’ve told it which file handle to use and so the system knows where to read the data from.

Append this to the text box we emptied earlier, with a carriage-return & line-feed. Given that we are reading line-by-line, we’re preserving the line-endings when putting the text in to the text box. Appending means we’re keeping what was there and adding to it.

Keep doing this until we’ve reached the end of the file. The EOF() function takes a file handle and says whether we’ve reach the *E*nd *O*f the *F*ile. Remember that the end of our loop terminates if the expression is true. Well, EOF() returns true if we’ve reached the end of the file. A good time to stop reading it, don’t you think? ๐Ÿ™‚

Close the file handle. Enough said! ๐Ÿ™‚

To Summarise

This code snippet reads in a file line-by-line and puts the contents in a textbox, preserving the line-endings.

Issues

  • intMsg is never used.
  • Neither is studentname
  • As mentioned earlier, you’re missing the file_error label and the end of the sub-routine (End Sub).

Related Solutions

What are the available Signals in Java

Eventually I brute forced the single to 5 character length signals and got these: BREAK (21) SEGV (11) ILL (4) FPE (8) TERM (15) ABRT (22) INT (2) The code: Set<String> signals = new HashSet<>(); String currentSignalStr; for (char i = 'A'; i <=...

Understanding unique keys for array children in React.js

You should add a key to each child as well as each element inside children. This way React can handle the minimal DOM change. In your code, each <TableRowItem key={item.id} data={item} columns={columnNames}/> is trying to render some children inside them...

most efficient AABB vs Ray collision algorithms

Andrew Woo, who along with John Amanatides developed the raymarching algorithm (DDA) used ubiquitously in raytracers, wrote "Fast Ray-Box Intersection" (alternative source here) which was published in Graphics Gems, 1990, pp. 395-396. Rather than being built...

What is the difference between #!/bin/sh and #!/bin/bash?

bash and sh are two different shells. Basically bash is sh, with more features and better syntax. Most commands work the same, but they are different. Having said that, you should realize /bin/sh on most systems will be a symbolic link and will not invoke sh....

How to pass password to mysql command line

The mysql client utility can take a password on the command line with either the -p or --password= options. If you use -p, there must not be any blank space after the option letter: $ mysql -pmypassword I prefer the long options in scripts as they are...

how to leave a gap in select list from left [closed]

Maybe you were after something like: <select style="padding: 0 0 0 10px"> <option>Male</option> <option>female</option> <option>other</option> </select> jsFiddle example here. Is that what you wanted? Edit: After...

How to use multiple condition in one foreach loop?

Use two loops: foreach ($products as $product) { foreach ($categories as $category) { // using $product and $category } } I had the same question today as the OP. I figured I can split up the problem by first merging the two arrays and then performing the...

Why do Primitive Data Types have a Fixed Size?

As low-level programming languages, the designs of C and C++ closely follow what common hardware is capable of. The primitive building blocks (fundamental types) correspond to entities that common CPUs natively support. CPUs typically can handle bytes and words...

how do i count the words in a string list

Shouldn't it be string[] words = s.Split(' '); Even if we say your word is s.Split(' '); then it should be string[] words = word not string[]=word And to count how much words are in that array just do int howManyWords = words.Length; Also if you want to go...

Data from text file to dataframe

Here you go! It's really fast. For a file with ~11 million lines (made by copying and pasting your sample file over and over again), it took about 22 seconds on my machine, and produced a dataframe with 2.2 million rows. Note: I wasn't sure quite how to handle...

Unexpected output when creating a List of Lists in Java

You are adding all the integers to the same inner list (the one that you create at the start of your method with the statement List<Integer> l1 = new ArrayList<Integer>();). You should create a new List before adding elements to it: for(int i=1;...

how to calculation cost time [closed]

I think I understand what you're asking. You just want to have a new dataframe that calculates the time difference between the three different entries for each unique order id? So, I start by creating the dataframe: data = [...

how to disable button on change using jquery

you can do this as am assuming a image and am checking the resolutions and then i disable or enable the button as per requirements and also am clearing selected image so user can't upload the wrong format . <script> var _URL = window.URL ||...

Detect and uninstall antivirus

You could try the following, from https://community.spiceworks.com/scripts/show/3161-detect-and-remove-software-powershell: ################################################ # Powershell Detect and Remove software script # # # # V1.0 - Gav #...

return statement in c ??? why this function always returning 20?

You have a problem in your code. Change scanf("%d",arr[i]); To scanf("%d",&arr[i]); This is done because scanf expects an argument of type int* but you provide argument arr[i] which is of type int. Also add a check that ends the program if user inputs a...

How to add Bootstrap? [closed]

By adding the CDN <html> <head> <title>Cube</title> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> <!-- Latest compiled and minified CSS --> <link rel="stylesheet"...