Archive for the 'VB.NET' Category

Working With A Simple Structure Array In VB.NET

Recently asked in Yahoo! Answers:

In Visual Basic.NET how do you assign a grading scale to an array of structure variables?

I want to assign a grading scale to an array of structure variables. HOW do you assign a range of values, such as 0 to 299, to a variable within a structure? (In Visual Basic.NET)

Example:
‘declare array of structure variables
Dim graGradingScale(4) As Grades
Dim intSearchfor As Integer
Dim intX As Integer = 0

‘assign grading scale to the array
graGradingScale(0).intPoints = 0 to 299
graGradingScale(0).strGrades = “F”

The part that needs to be changed is “0 to 299″ . How do you assign this range of values to the variable, so that if the user enters a 7, for example, the grade that will match that number will be “F”? I have the rest of the code done correctly, except this one part.

Here is the Grades structure:

Structure Grades
Public intPoints As Integer
Public strGrades As String
End Structure

As I understand the question, what this questioner wants is to create a five-cell array — each cell corresponding to a letter grade of A, B, C, D or F — and assign both the letter grade and the range of numbers needed to obtain that grade into a Structure (struct, for you C-language folks).

Then, she wants to be able to run an input value through the array, to see what letter grade the person should get.

Well, that’s pretty straightforward, but we need to make a couple minor modifications to the questioner’s methodology to make this work as desired. So let’s get to it.

Read the rest of this entry »

Retaining The LastWriteTime Value For A File About To Be Overwritten Via FTP / FileUpload By Using ASP.NET’s FileInfo Class

Recently asked on Yahoo! Answers:

Preserving last modified date when uploading (asp.net)?

I need to preserve (or change) the last modified date in the file headers when uploading via ftp. When I upload a file via ftp, the last modified date will be the date of upload. Creation date would be fine too. I just need to have the original date attached somewhere in the attributes.

Does anyone have a creative solution. For instance, can I create a container with custom attributes and then stream the data into it? If so how would I do it? Links and/or code would be greatly appreciated. Also, I am using vb.net but C# is fine too.

Keep in mind I must pass credentials to the remote server.

This is actually fairly straightforward, thanks to the FileInfo class in .NET — it’s a subclass of the FileSystemInfo class, which is a replacement of the FileSystemObject of yore.

And much like the old FileSystemObject class, FileInfo not only allows us to do some basic things with files — open, close, read, write and delete, for example — it also allows us to get or set certain properties within a file, including LastWriteTime. We’ll exploit that to achieve what this questioner wants.

Read the rest of this entry »

Objects (Classes) Explained In Very Simple Terms

One of the most common questions on Yahoo! Answers is how classes or objects, or the parts of a class / object, such as properties, methods and events, work.

Here’s a gross simplification of how classes and objects work. Most of this is lifted from a previous blog entry, Interpreting A C# Class Code Structure.

Classes / Objects

A class or object is a way of combining all sorts of data that relates to a single thing in one place, and a way of associating functions with that data. (For most intents and purposes, classes and objects are the same thing. Whenever I use the term class, I also mean object; whenever I use object, I also mean class. More on that in a moment.)

For example, you can think of a human as a class.

In the human class, you are an instance. For example, you might think that God decided to run this code when you were born:

Dim you As New HumanBeing()

What He did was create a variable, named you, and set the value of that variable to be an instance of the HumanBeing object. An instance is the actual use of an object. The object is the mold; the instance is the actual thing you made from the mold.

(Most programmers use the term class when they are speaking about an instance, and object when they are talking in general terms, so that’s the real difference between class and object. However, you can generally use the two terms interchangeably when discussing a specific programming issue.)

Read the rest of this entry »

An ASP.NET 2.0 Script To Share Files Among Users

Recently asked on Yahoo! Answers:

How could I enable user to upload and download file from server using asp.net 2?

How could I enable a user to upload file to the server and then view link to download this file from the server to anthor user i when he enters the site using ASP.NET 2?

The problems here could be handled very easily simply by using the built-in FileUpload class and the DirectoryInfo / FileInfo classes to display the files in the targeted directory.

So, let’s run that simple code today.

Read the rest of this entry »

The Difference Between Data Adapters, Data Sets And Data Readers, In Plain English

Recently posed on Yahoo! Answers:

Data reader or Data adapter?

in database programming what is the difference between these?
please tell me completely.(I am begginer)

A data adapter is a thing you use to connect and send commands to a database. A data reader is a thing you use to output records one at a time, and only going foward (from record 1 to the last record).

And the thing he didn’t ask about — the item you use to hold the records you get from a data adapter, so you can work with them — is a data set.

So, in order: You first create a data adapter to connect to a database, send your SQL to it and get a response. You then populate either a data set or a data reader from the response the data adapter gets. If you put the records in a data set, you can work with them; if you put them in a data reader, you can only output them.

Read the rest of this entry »