Archive for the 'VB.NET' Category

Getting Plain Text From An ASP.NET 2.0 Page For Use As An AJAX Data Source

In a follow-up comment to my answer on his AJAX question on Yahoo! Answers, mzanime2000 posed a problem faced by many ASP.NET programming beginners: how to get ASP.NET to return plain text only for use in AJAX.

Wow thanks! Pretty nice well-detailed response. Now I just hope I can get it to work with ASP.NET, I see that you used PHP in your example. One thing I still dont get though, is how Ajax invokes the SQL data when it looks like you used PHP to do the msql_connect part. And PHP is pre-processed too

ASP.NET is based around two output models: HTML and XML. The whole approach assumes you’re either going to spit out a Web page or some XML at the end of the process. Thus, all the controls, all the tutorials … everything is aimed at outputting HTML or XML. But for an AJAX data source such as the type I discussed in my previous blog entry, you need plain text.

The fix is to remove all HTML formatting from the ASPX page, and place our code directly into the ASPX page itself. That will let us call upon Response.ContentType, which will send our database results as text — which is just what our Google Maps API, and all other AJAX applications, want to see.

Read the rest of this entry »

In Reply To Comments Made On “Working With A Simple Structure Array In VB.NET”

Olive Oyl left the following comment in response to my blog post, “Working With A Simple Structure Array In VB.NET,” which responds to her Yahoo! Answers question:

Thank you!

I really appreciate all of the time and effort, and thought that has obviously gone into this answer.

I had already figured out the answer to the problem, and it is the same as what you have said here. This is really cool, the way this has been answered!

The other thing I was doing wrong with this problem is that the array must be declared in the public area of the form (I am not sure of the correct name for that area).

The instructor’s requirement was that the array should only be populated one time, when the form loads. That means that the display click event needs to be able to access it, so it has to be declared in the public area.

Thanks again! Hopefully this information will help others who are learning VB.NET.

p.s. I am almost certain that it is impossible to “assign a range of values, such as 0 to 299, to a variable ” as I tried to do.

I know that a scalar variable can hold ONLY one value at a time.

(Actually, she had left two comments, the second being a copy of her code, but it was incomplete due to the limitations of size in my blog comments box. I’ll update this post with her code if she wants to e-mail it to me for posting.)

There are a few parts of this comment I’d like to respond to more completely than I can in a follow-up comment, so here’s a second blog post on the subject.

Read the rest of this entry »

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 »