• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

*sigh*

I don't know how to do any of that.

Okay, start with the simplest thing.

You can probably check if a radio button for your burger was selected with

Code:
radBurger.Checked

So we can create a variable to hold our subtotal with

Code:
Dim varSubtotal As Double = 0.00

Then we can check that radio button and add to our subtotal as necessary.

Code:
If radBurger.Checked Then
    varSubtotal = varSubtotal + 5.02
End If

Assuming that burger cost $5.02.

Hope that gets you started. Conditional statements, create variables, simple math with variables.

EDIT: A more clear way of declaring variables and setting their values would be this:

Code:
Dim varSubtotal As Double

varSubtotal = 0.00
 
Too bad I don't know what the first step even is. Maybe my professor can help ( she won't)
Well, what do you have working? Any UI stuff, or just the underlying guts?

To me, what you have are some fairly concrete tasks:
1. how do I draw stuff to the screen?
2. how do I accept input?
3. how do I actually do the calculations internally?
4. how do I save the history?
5. how do I "recall" the history?

I think you're right to leave the history stuff for last, it'll be a decent bit of work for something that's not core functionality.
 
Believe it or not there are architectures (and thus compilers targeting said architectures) that violate that. I can't remember which one - I believe it was a Texas Instruments compiler - the C55x. sizeof(char) returned 1 (I believe the standard dictates that sizeof(char) must always be 1, and you should be able to rely on this, though whether any given compiler is actually standards compliant is another topic), and it was using 16 bit bytes - sizeof was returning values in terms of multiples of 16 bit bytes due to their byte being 16 bits long. So no, you technically can't rely on 1 byte being 8 bits - except you basically can for the large large majority of current architectures.

I wrote this long message about how you're wrong, and then I went and looked up the Wikipedia page for byte and found out that you're half-right. I say half because it links to IEC 80000-13 which officially declared a byte to be 8 bits. It's certainly interesting to know that a byte did not used to always be 8 bits :)

On the subject of char, the standard actually does not dictate that sizeof(char) == 1 believe it or not. Here's what it says:

Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set.

It doesn't say "and no larger", it just says large enough.
 

XenodudeX

Junior Member
Okay, start with the simplest thing.

You can probably check if a radio button for your burger was selected with

Code:
radBurger.Checked

So we can create a variable to hold our subtotal with

Code:
Dim varSubtotal As Double = 0.00

Then we can check that radio button and add to our subtotal as necessary.

Code:
If radBurger.Checked Then
    varSubtotal = varSubtotal + 5.02
End If

Assuming that burger cost $5.02.

Hope that gets you started. Conditional statements, create variables, simple math with variables.

EDIT: A more clear way of declaring variables and setting their values would be this:

Code:
Dim varSubtotal As Double

varSubtotal = 0.00

I don't understand. Am I supposed to put that in every radbutton?

and
Code:
 Dim varSubtotal As Double

varSubtotal = 0.00

gives an error
 
I'm not quite sure where you are stuck here, but I think it would help iiiif;

1. You take a little time to sketch out ideas in a notebook, regarding what you think could work. I do this all the time, I don't usually spend more than a few hours at the computer just banging things out and seeing what happens. The notebook is a good way of keeping your thoughts together, and avoiding repeating stuff or losing your train of thought. Always good to look back to see what you've tried before coming up with new ideas.

2. You could list a set of goals regarding exactly what nuances you want to tackle first.

3. You could share about what was the last thing you learned about VB. If the array is foreign to you, let us know so we can avoid solutions involving data structures. (though I'm sure your professor would be impressed if you used one somehow.)

I've got 4 text boxes, 2 are read only. The first read only box contains the solution, the second is to contain the formula. The formula is what I need help with.

Basically when program runs you should enter a number in box 1 and box 2 and press the add button, box 3 displays the solution, box 4 displays the formula.

I'm sure this is super basic stuff, but I can't think of a way to get that equation to show in plain text.
 
thanks for the breakdown. I was aware of most of what you wrote. I was wondering if memory addresses outside of the cpu registers load only a byte. But as you said the smallest addressable unit is a byte. all the answers here have helped
edit: never mind got it.

You say you got it. But just in case, I'm not really sure what the bolded sentence means. For one thing, I'm not sure what memory addresses "outside" of the CPU registers are or why they would be any different than memory addresses "inside" CPU registers. Secondly, addresses don't "load" anything. CPU instructions do. Addresses are the source from which the loads occur. Do their exist CPU instructions which can load exactly 1 byte? Yes. With the instruction mov al, [ebp] the CPU will look at the value in register EBP. It will be a 32 bit number, which it will it will treat as a memory address, read 1 byte from that location, and store it in the register al. Whatever value was in the upper 24 bits of EAX will be unaltered.
 
I don't understand. Am I supposed to put that in every radbutton?

and
Code:
 Dim varSubtotal As Double

varSubtotal = 0.00

gives an error

I think you need to take a step back and really think through what you are doing, and what I'm describing. (or take a nap, if you've been doing this for too long you might not be in the right state of mind for this...)

Did you place

Code:
Dim varSubtotal As Double

varSubtotal = 0.00

Somewhere after an instance of

Code:
Dim varSubtotal As Double = 0.00

Because redeclaring the variable like that when the variable is still in scope is probably not going to work in Visual Basic. I was just showing two different ways of declaring "varSubtotal", the results are exactly identical.

Otherwise, that should be valid code as written; I don't have a VB compiler to test with, but it it's equivalent to what other tutorials show.

I've given you the individual pieces you need. What's left is to take some time to figure out where they should go, and how you'd like to organize this.
 

Rapstah

Member
I've got 4 text boxes, 2 are read only. The first read only box contains the solution, the second is to contain the formula. The formula is what I need help with.

Basically when program runs you should enter a number in box 1 and box 2 and press the add button, box 3 displays the solution, box 4 displays the formula.

I'm sure this is super basic stuff, but I can't think of a way to get that equation to show in plain text.

Setting the text in box 4 to "(contents of box 1) (the clicked button) (contents of box 2) = (contents of box 3)" seems like it should be a pretty simple operation if you know how to concatenate strings. I don't know what language or system you're working in.
 
Setting the text in box 4 to "(contents of box 1) (the clicked button) (contents of box 2) = (contents of box 3)" seems like it should be a pretty simple operation if you know how to concatenate strings. I don't know what language or system you're working in.

Following up, MSDN has a section on concatenation with Strings in Visual Basic.

The examples should show you all you need to combine strings together to make a new string.
 
Setting the text in box 4 to "(contents of box 1) (the clicked button) (contents of box 2) = (contents of box 3)" seems like it should be a pretty simple operation if you know how to concatenate strings. I don't know what language or system you're working in.

Dim number1 As Double
Dim number2 As Double
Dim answer As Double


number1 = inputBox1.Text
number2 = inputBox2.Text
answer = number1 + number2
resultBox.Text = answer

I'm a novice at best, I've taken some theory courses and what not, but this is mostly what I have for basic addition. I can't figure how to get that data to fill box 4
 
Dim number1 As Double
Dim number2 As Double
Dim answer As Double


number1 = inputBox1.Text
number2 = inputBox2.Text
answer = number1 + number2
resultBox.Text = answer

I'm a novice at best, I've taken some theory courses and what not, but this is mostly what I have for basic addition. I can't figure how to get that data to fill box 4

So assuming you can read from box 4, you should have something like
Code:
box4.Text

And as you're pressing buttons, you can just do
Code:
box4.Text = box4.Text + "2 "

I think that's a good place to start. Again, this is all based on the MSDN String concatenation docs.
 
Setting the text in box 4 to "(contents of box 1) (the clicked button) (contents of box 2) = (contents of box 3)" seems like it should be a pretty simple operation if you know how to concatenate strings. I don't know what language or system you're working in.

So assuming you can read from box 4, you should have something like
Code:
box4.Text

And as you're pressing buttons, you can just do
Code:
box4.Text = box4.Text + "2 "

I think that's a good place to start. Again, this is all based on the MSDN String concatenation docs.


So I added
Code:
calculationBox.Text = number1 & "+" & number2 & "=" & answer

And that has appeared to get me what I needed.

It kinda dumb the way colleges frame their curriculum, to where they teach you all of these things on paper, in books, like you're supposed to retain it when it comes around to another class that actually deals with coding. I'll never understand it. Basically most of my knowledge of coding comes from JavaScript because that was the only thing I was forced to do. I need to do better in coding on my own time, thanks for the help guys.
 

Nesotenso

Member
You say you got it. But just in case, I'm not really sure what the bolded sentence means. For one thing, I'm not sure what memory addresses "outside" of the CPU registers are or why they would be any different than memory addresses "inside" CPU registers. Secondly, addresses don't "load" anything. CPU instructions do. Addresses are the source from which the loads occur. Do their exist CPU instructions which can load exactly 1 byte? Yes. With the instruction mov al, [ebp] the CPU will look at the value in register EBP. It will be a 32 bit number, which it will it will treat as a memory address, read 1 byte from that location, and store it in the register al. Whatever value was in the upper 24 bits of EAX will be unaltered.

I was talking about memory addresses other than processor registers. Say for example when assembly instruction loads a value into memory address with a hex value as the operand. like ram access I guess.
 

XenodudeX

Junior Member
I think you need to take a step back and really think through what you are doing, and what I'm describing. (or take a nap, if you've been doing this for too long you might not be in the right state of mind for this...)

Did you place

Code:
Dim varSubtotal As Double

varSubtotal = 0.00

Somewhere after an instance of

Code:
Dim varSubtotal As Double = 0.00

Because redeclaring the variable like that when the variable is still in scope is probably not going to work in Visual Basic. I was just showing two different ways of declaring "varSubtotal", the results are exactly identical.

Otherwise, that should be valid code as written; I don't have a VB compiler to test with, but it it's equivalent to what other tutorials show.

I've given you the individual pieces you need. What's left is to take some time to figure out where they should go, and how you'd like to organize this.

Alright, so I've tinkering with the code and I eventually added this :

Code:
End If
        If radYes.Checked Then
            If varSubtotal >= 14.0 Then
                varSubtotal = varSubtotal + 0.0
            End If
        End If

and it seems to be getting the subtotal of all of the meals that were selected! But... I'm getting this output:
menuefrm5.png


I just want one subtotal amount. What am I doing wrong?

I have
Code:
        If radMeatloaf.Checked Then
            varSubtotal = varSubtotal + 9.25
            lstReceipt.Items.Add("Subtotal" & Chr(9) & varSubtotal.ToString("C"))
        End If

for each of the meals ( pancakes, burgers, etc) could lstReceipt line be the culprit?
 
I wrote this long message about how you're wrong, and then I went and looked up the Wikipedia page for byte and found out that you're half-right. I say half because it links to IEC 80000-13 which officially declared a byte to be 8 bits. It's certainly interesting to know that a byte did not used to always be 8 bits :)

On the subject of char, the standard actually does not dictate that sizeof(char) == 1 believe it or not. Here's what it says:



It doesn't say "and no larger", it just says large enough.

Actually, going by the C++11 standard, here is a quote:

"5.3.3 Sizeof [expr.sizeof]
1 The sizeof operator yields the number of bytes in the object representation of its operand. The operand is
either an expression, which is an unevaluated operand (Clause 5), or a parenthesized type-id. The sizeof
operator shall not be applied to an expression that has function or incomplete type, to an enumeration
type whose underlying type is not fixed before all its enumerators have been declared, to the parenthesized
name of such types, or to an lvalue that designates a bit-field. sizeof(char), sizeof(signed char) and
sizeof(unsigned char) are 1. The result of sizeof applied to any other fundamental type (3.9.1) is
implementation-defined.
[ Note: in particular, sizeof(bool), sizeof(char16_t), sizeof(char32_t), and
sizeof(wchar_t) are implementation-defined.74 —end note ] [ Note: See 1.7 for the definition of byte
and 3.9 for the definition of object representation. —end note ]"

Whether this is different in any other standard, I don't know. The C++11 standard is the first I've owned a copy of, and I don't know if the C++14 standard has any changes in this respect.

I agree with you that a byte is 8 bits, and that it's an accepted standard - I was merely stating that there are contexts in which that definition does not apply. This is admittedly being extremely pedantic.
 
Alright, so I've tinkering with the code and I eventually added this :

Code:
End If
        If radYes.Checked Then
            If varSubtotal >= 14.0 Then
                varSubtotal = varSubtotal + 0.0
            End If
        End If

and it seems to be getting the subtotal of all of the meals that were selected! But... I'm getting this output:
menuefrm5.png


I just want one subtotal amount. What am I doing wrong?

I have
Code:
        If radMeatloaf.Checked Then
            varSubtotal = varSubtotal + 9.25
            lstReceipt.Items.Add("Subtotal" & Chr(9) & varSubtotal.ToString("C"))
        End If

for each of the meals ( pancakes, burgers, etc) could lstReceipt line be the culprit?

You're on the right track. What you want is to amend to listReceipt just before you write out the Tax to that receipt.

So this line probably shouldn't be in your if statement
Code:
lstReceipt.Items.Add("Subtotal" & Chr(9) & varSubtotal.ToString("C"))
You only want to do that right before printing the tax out to the receipt.

Most of programming is figuring out how to organize stuff. That's all this is.


EDIT: One more thing...
Code:
varSubtotal = varSubtotal + 0.0
Exactly as written, this line is just taking what was stored in varSubtotal, adding 0.0 to it, and storing it in varSubtotal. As quoted, this specific line isn't doing anything useful.

You only need to assign 0.0 to varSubtotal without adding the previous subtotal when you want to set the value (0.0) to start at, or reset your subtotal so you don't have to worry about the result of the previous calculations. It's up to you to figure out when you want to set or reset varSubtotal to 0.0. You should only need to do it once in code.
 

diaspora

Member
I really, really, really don't like perl, worse is learning it from someone who wants us to work on stuff we haven't been taught yet.

edit: I'm supposed to have index.html link to auth.pl. auth.pl should ask for username and password, that's fine. Problem is that I hit a 404 everytime I try clicking my link to auth.pl, I can't tell if it's an issue with my perl file or the html file.
 
I was talking about memory addresses other than processor registers. Say for example when assembly instruction loads a value into memory address with a hex value as the operand. like ram access I guess.

That's the thing: processor registers are not memory. They don't have addresses. So when you say "memory addresses other than processor registers ", I'm not sure what you mean, because that's the same as all memory
 

Nesotenso

Member
That's the thing: processor registers are not memory. They don't have addresses. So when you say "memory addresses other than processor registers ", I'm not sure what you mean, because that's the same as all memory

Yeah I should have worded it better. What I meant was that unlike memory addresses, registers like EAX etc. can hold more than a byte.
thanks for the answers.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Memory can hold more than a byte as well.

I feel like you are over thinking this and causing yourself to misunderstand.
 

Nesotenso

Member
Memory can hold more than a byte as well.

I feel like you are over thinking this and causing yourself to misunderstand.

but aren't theoretical RAM limits for different bit architectures based on the assumption that a memory address holds a byte ? or is that just the minimum?

The smallest addressable unit of memory is 1 byte. Remember that every operation has to go through registers, and the registers are 64 bits or 32 bits depending on platform. But the registers are subdivided. On x86, EAX is 32 bits. But you can address the low 2 bytes of this register as ax. And you can address the high and low bytes of ax as ah and al, respectively. But you can't go smaller. So 1 byte is the smallest unit of memory you can load.

edit: I think the above explanation helped. That smallest addressable unit is byte( as the last 16 bits of ax are divided into high and low). Say for example I have mov eax, [source]
so whatever value I have in source should at least 8 bits, but I can have up to 32 bits. Did I understand that right?
 

XenodudeX

Junior Member
You're on the right track. What you want is to amend to listReceipt just before you write out the Tax to that receipt.

So this line probably shouldn't be in your if statement
Code:
lstReceipt.Items.Add("Subtotal" & Chr(9) & varSubtotal.ToString("C"))
You only want to do that right before printing the tax out to the receipt.

Most of programming is figuring out how to organize stuff. That's all this is.


EDIT: One more thing...
Code:
varSubtotal = varSubtotal + 0.0
Exactly as written, this line is just taking what was stored in varSubtotal, adding 0.0 to it, and storing it in varSubtotal. As quoted, this specific line isn't doing anything useful.

You only need to assign 0.0 to varSubtotal without adding the previous subtotal when you want to set the value (0.0) to start at, or reset your subtotal so you don't have to worry about the result of the previous calculations. It's up to you to figure out when you want to set or reset varSubtotal to 0.0. You should only need to do it once in code.

Alllright. So typing in
Code:
  Private Sub radNo_CheckedChanged(sender As Object, e As EventArgs) Handles radNo.CheckedChanged
        If radNo.Checked = True Then
            lstReceipt.Items.Remove(("Tax" & Chr(9) & Chr(9) & 0.07.ToString("C")))
            lstReceipt.Items.Remove("Total")
            [b]varSubtotal = 0.0[/b]
        End If
    End Sub

seems to work. Now, to get that total, I have multiply the sub total with the tax. Is this pretty much the same method as getting the subtotal?

So say....
Code:
 dim varTotal as Double = .07
 
but aren't theoretical RAM limits for different bit architectures based on the assumption that a memory address holds a byte ? or is that just the minimum?

Each memory address holds 1 byte, yes. Addresses are just numbers after all, it would be very unusual if the normal rules of arithmetic didn't apply to memory addresses. If you load from a memory address into the register, it will load a number of bytes corresponding to the size of the register. So if you load from memory into EAX, it will load 4 bytes. If you load from memory into AX, it will load 2 bytes. If you load from memory into AH or AL, it will load 1 byte.
 

Nesotenso

Member
Each memory address holds 1 byte, yes. Addresses are just numbers after all, it would be very unusual if the normal rules of arithmetic didn't apply to memory addresses. If you load from a memory address into the register, it will load a number of bytes corresponding to the size of the register. So if you load from memory into EAX, it will load 4 bytes. If you load from memory into AX, it will load 2 bytes. If you load from memory into AH or AL, it will load 1 byte.

just one more question, are you loading the address here or the value contained at the address ?

&A loads the address
A loads the value

meant in assembly. or do we use the same notation with ampersand in assembly as well?
 
just one more question, are you loading the address here or the value contained at the address ?

Depends how you write the code. You can write code to do either. Although it's very terse, the Intel Programmer's Manual is very helpful in this regard. In this case, take a look at Vol. 2A 3-509, and it lists all the formats a mov instruction can take. Here are a couple of formats of interest:

MOV r8,r/m8 (Move 8-bit memory/register value into an 8-bit register)
MOV r32,r/m32 (Move 32-bit memory/register value into a 32-bit register)
MOV r8,imm8 (Move immediate -- e.g. constant -- 8-bit value into an 8 bit register)
MOV r32,imm32 (Move immediate -- e.g. constant -- 32-bit value into a 32 bit register)

The first two allow you to move from an [8/32]-bit memory address or register to an [8/32]-bit register. An example of moving from an 8 bit memory address to an 8 bit register would be MOV AL, [0x12345678]. This will move 1 byte from address 0x12345678 into AL, the lower 8 bits of the 32-bit EAX register.

The brackets indicate that it should treat the value as an address, and fetch the value at the memory location. If you leave the brackets off, you get MOV AL, 0x12345678. This triggers the "immediate" form of the instruction. This tries to move the number 0x12345678 into AL. But it fails, because of a size conflict. 0x12345678 is a 32-bit value, and AL is an 8-bit register. MOV r8, imm32 is not a valid form of the instruction. On the other hand, both of the following work:

MOV EAX, [0x12345678] // Move 4 bytes from address 0x12345678 into EAX
MOV EAX, 0x12345678 // Move the number 0x12345678 into EAX
 
Alllright. So typing in
Code:
  Private Sub radNo_CheckedChanged(sender As Object, e As EventArgs) Handles radNo.CheckedChanged
        If radNo.Checked = True Then
            lstReceipt.Items.Remove(("Tax" & Chr(9) & Chr(9) & 0.07.ToString("C")))
            lstReceipt.Items.Remove("Total")
            [b]varSubtotal = 0.0[/b]
        End If
    End Sub

seems to work. Now, to get that total, I have multiply the sub total with the tax. Is this pretty much the same method as getting the subtotal?

So say....
Code:
 dim varTotal as Double = .07
Yeah, you're getting the hang of it. Create variables for storage, add and multiply as necessary.

You could hold the subtotal's computed tax in a new variable, if you'd like, and it would probably be more readable that way than having to juggle that tax in the varTotal variable.

Again, most of programming is organization. You'll have to figure out on your own what you're most comfortable with, there, and there's a few good practices out there that you'll hear about if you choose to stick with programming. Though, I find no two programmers agree on exactly the same ones.
 

XenodudeX

Junior Member
Yeah it seems to be working, but I'm getting these really weird/big numbers for the final total.

Maybe I should be adding the tax instead of multiplying

edit: Derp. Gotta add and multiply

edit2: Hmm.. pretty sure I'm not doing this right.

I tried using this :
Code:
 Vartotal= varTotal +( varSubtotal * vartotal)
then I got this

Then I tried this :
Code:
 varTotal = varSubtotal + (varTotal * varSubtotal)
in which I got this:
 
Your math looks right, but you need to reset the values stored in varSubtotal and varTotal (and any others you're using) to 0.0 just before you make a new set of calculations.

Otherwise, it's going to keep building off of past calculations, and things will get huge.

It's exactly like what happens when you keep on adding or multiplying with your calculator without clearing the past result. I believe that's what you're seeing right now. Calculators are computers, too. :)


EDIT: My math comment is assuming for
Code:
varTotal = varSubtotal + (varTotal * varSubtotal)
varTotal has 0.07 stored in it right before you're making this calculation. As long as that's true, that should be right.

Don't be afraid to print out varSubtotal and varTotal at various points in your program to make sure that the numbers are changing in ways you expect. When thinking in terms of functions and not just simple, sequential logic, it can be hard to understand what's causing side effects where.
 

XenodudeX

Junior Member
Your math looks right, but you need to reset the values stored in varSubtotal and varTotal (and any others you're using) to 0.0 just before you make a new set of calculations.

Otherwise, it's going to keep building off of past calculations, and things will get huge.

It's exactly like what happens when you keep on adding or multiplying with your calculator without clearing the past result. I believe that's what you're seeing right now. Calculators are computers, too. :)


EDIT: My math comment is assuming for
Code:
varTotal = varSubtotal + (varTotal * varSubtotal)
varTotal has 0.07 stored in it right before you're making this calculation. As long as that's true, that should be right.

Don't be afraid to print out varSubtotal and varTotal at various points in your program to make sure that the numbers are changing in ways you expect. When thinking in terms of functions and not just simple, sequential logic, it can be hard to understand what's causing side effects where.

Yeah I have
Code:
varTotal = varSubtotal + (varTotal * varSubtotal)
and
Code:
 Dim varTotal As Double = 0.07
, but I'm still getting the huge numbers.

And I;m also using

varTotal = 0.0
varSubtotal = 0.0

also when radNo is checked
 
You're very close, then. If this assignment's not due in 24 hours or very soon (...I was in college too, so I have a hunch), I'd recommend consulting the professor for this or see if you can butt heads with a classmate or two.

In the future, to help with this sorta work, it would be a good idea to pursue a study group or get an early start on it so you can ambush the professor for questions as early as possible.

Programming is very different from other works taught in school, very hard at first, and it takes awhile to build up a rhythm where you grow comfortable with it, know where to look for problems, how you prefer to structure things to have the fewest bugs and side effects.

Back when I was in college, the students used to bemoan how our GPAs would be lower than the other science majors because the work was often much harder to get "right". That's probably not far from the truth.
 

XenodudeX

Junior Member
I thiiink I found the problem. I should of had
Code:
varTotal = varSubtotal + (0.07 * varSubtotal)

All of the totals look pretty accurate now
 

NotBacon

Member
Get very used to Googling things in the right way to get those awesome StackOverflow answers lol

And are you writing pseudo-code before actual code? It's never helped me but some of my friends swear by it. So before things get messy you get out a piece of paper (or text editor) and write something simple like:

Code:
' Assign all prices chicken = 10, steak = 15, salmon = 20, etc.

main:
    ' setup UI
    ' setup initial checkbox states
    ' do other totally important subroutines

when checkbox1 is clicked:
    ' check value of checkbox
    ' if it's checked then show all the breakfast items
    ' if not then set value1, value2, and value3 to false

checkbox2...
checkbox3...
etc.

when Print Receipt is clicked:
    ' go (loop) through all of the values in the list (array) one by one
        ' if the current item in the list is true then add to total
    ' end of loop
    ' add tax to total
    ' display total
...

Or something like that. Then you can kind of use it as a guide while you write real code.
 
Stack Overflow is... controversial in some places I've worked.

The trouble is that it will often give you an answer, but the answerer won't tell you how they got there, or what documentation they used, or how they arrived to that conclusion. So you're kind of helpless for additional info, and it leaves you without a well rounded understanding of programming.

In addition, it's not uncommon to find an answer on SO that "works", but ends up being unhelpful and hacky in the long term.. the kind of solution that will bite you in the butt, later.

SO's fine for quick hints from time to time, if you're willing to take a gamble on it. But it's not a good primary source.

When it comes to programming, crowdsourcing doesn't work as well as published documentation or computer books.
 

leroidys

Member
Stack Overflow is... controversial in some places I've worked.

The trouble is that it will often give you an answer, but the answerer won't tell you how they got there, or what documentation they used, or how they arrived to that conclusion. So you're kind of helpless for additional info, and it leaves you without a well rounded understanding of programming.

In addition, it's not uncommon to find an answer on SO that "works", but ends up being unhelpful and hacky in the long term.. the kind of solution that will bite you in the butt, later.

SO's fine for quick hints from time to time, if you're willing to take a gamble on it. But it's not a good primary source.

When it comes to programming, crowdsourcing doesn't work as well as published documentation or computer books.

I've found some very, very detailed answers and insightful debate on SO quote often. I think it's the best programming resource on the internet, honestly.
 
I've found some very, very detailed answers and insightful debate on SO quote often. I think it's the best programming resource on the internet, honestly.
Giving credit where it's due, SO is a hell of a lot better than the site it replaced.

Experts-Exchange. HOO BOY. That used to be exclusively a pay site, where the questions were free but you'd have to subscribe for answers. And to top it off, the answers were almost always of extremely low quality.
 

diaspora

Member
Before I tear my hair out, I think I'll post my query here. I'm supposed to create a "login" type page. I've got postBack there since I don't want to display "error" until someone actually fails to login. None of this actually works though. I'm getting an internal server error every time I try to run it in IE.

Code:
#!/usr/bin/perl

use CGI qw( :standard );

$username = param( "q1" );
$password = param( "q2" );
$postBack = param("postBack");

print "Content-type: text/html\n\n";

print "<html>";
print "<head><title>auth.pl</title></head>";
print "<body>";
print "<BR><BR>";

unless ($username eq "username" && $password eq "password")
{
    print "You submitted username";
    print "<form name='auth' action='auth.pl' method='post'>";
    print "Username:    <input type='text' name='username'>";
    print "<BR><BR>";
    print "Password:    <input type='password' name='password'>";
    print "<BR><BR>";
    print "<input type='submit' value='Submit'>";
    
    if ($postBack > 0)
    {
        print "Error";
    }
    
    print "<input type='hidden' name='postBack' value='1'>";
    print "</form>";
}

else
{
    print "stuff";
}

print "</body>";
print "</html>";
 
Not a Perl or a CGI person, but the first thing I'd try is to keep a backup of what you have right now (just make a copy of the Perl script), and see if you get the same error with just this:
Code:
#!/usr/bin/perl

use CGI qw( :standard );

$username = param( "q1" );
$password = param( "q2" );
$postBack = param("postBack");
And nothing else. Just to whittle down where things are totally falling apart. Strip away more code if necessary, an "internal server error" tells me that the problem is in the Perl script running on the server. Keep stripping things out until you know what runs and what's breaking.

The second thing, based on the "Programming Style" section of the Perl 5 CGI documentation, is that I THINK you need to load CGI with the standard functional routines in the following manner:
Code:
use CGI qw/:standard/;
Instead of
Code:
use CGI qw( :standard );
 

diaspora

Member
Not a Perl or a CGI person, but the first thing I'd try is to keep a backup of what you have right now (just make a copy of the Perl script), and see if you get the same error with just this:
Code:
#!/usr/bin/perl

use CGI qw( :standard );

$username = param( "q1" );
$password = param( "q2" );
$postBack = param("postBack");
And nothing else. Just to whittle down where things are totally falling apart. Strip away more code if necessary, an "internal server error" tells me that the problem is in the Perl script running on the server. Keep stripping things out until you know what runs and what's breaking.

The second thing, based on the "Programming Style" section of the Perl 5 CGI documentation, is that I THINK you need to load CGI with the standard functional routines in the following manner:
Code:
use CGI qw/:standard/;
Instead of
Code:
use CGI qw( :standard );

Internal server error every step of the way. ;_;

edit: not even hello world works holy shit
 
Internal server error every step of the way. ;_;

edit: not even hello world works holy shit
Okay, I think you'll have to check what's going on in your server.

First, see if Perl is set up correctly and if you can run scripts right there. Then, move on to the web server, make sure its interactions with Perl look good. There's something wrong there.
 

diaspora

Member
Okay, I think you'll have to check what's going on in your server.

First, see if Perl is set up correctly and if you can run scripts right there. Then, move on to the web server, make sure its interactions with Perl look good. There's something wrong there.

I agree. I just tried running the auth.pl of other students though, and theirs seem to be running swimmingly on the same server. I might just go ahead and submit this as is, marks be damned.
 
I agree. I just tried running the auth.pl of other students though, and theirs seem to be running swimmingly on the same server. I might just go ahead and submit this as is, marks be damned.
Another idea is that there may be some characters slipping in that Perl on your server isn't recognizing, and it's pooping out on that.

One thought is that if you've copy/pasted code from something like a PowerPoint slide (...not that I have ever done this, so long ago...), you might also copy some invisible characters that the Perl interpreter is going to look at, say what, and give up on. To get around this, it's a good idea to type all code by hand.

Another (and feel free to glaze over this for now, it's a bit far fetched) is the difference between UNIX style line endings and Windows/DOS style line endings in text files. Crazy as it sounds, Windows/DOS and UNIX, for historical reasons, handle a new line in text with different characters. For the former, it's a carriage return and line feed, the latter is just a line feed. It's highly unlikely that the Perl 5 interpreter will trip on this problem, but it's a known, goofy issue when parsing plain text files. If you've got students with problems on OS X (a UNIX) and Linux while the Windows students are just fine, or vice versa, this is probably it.
 

diaspora

Member
Another idea is that there may be some characters slipping in that Perl on your server isn't recognizing, and it's pooping out on that.

One thought is that if you've copy/pasted code from something like a PowerPoint slide (...not that I have ever done this, so long ago...), you might also copy some invisible characters that the Perl interpreter is going to look at, say what, and give up on. To get around this, it's a good idea to type all code by hand.

Another (and feel free to glaze over this for now, it's a bit far fetched) is the difference between UNIX style line endings and Windows/DOS style line endings in text files. Crazy as it sounds, Windows/DOS and UNIX, for historical reasons, handle a new line in text with different characters. For the former, it's a carriage return and line feed, the latter is just a line feed. It's highly unlikely that the Perl 5 interpreter will trip on this problem, but it's a known, goofy issue when parsing plain text files. If you've got students with problems on OS X (a UNIX) and Linux while the Windows students are just fine, or vice versa, this is probably it.

If I were to open up the .pl in the vi editor in the terminal, those characters should show up yes? I'll try with that.
 

Zeus7

Member
Code:
CREATE TABLE [dbo].[Booking] (
    [BookingID]        INT      IDENTITY (1, 1) NOT NULL,
    [CustomerID]       INT      NULL,
    [BookingDate]      DATE     NOT NULL,
    [BookingStartTime] SMALLINT NOT NULL,
    [BookingEndTime]   SMALLINT NOT NULL,
    [HourlyRate]       MONEY    NULL,
    PRIMARY KEY CLUSTERED ([BookingID] ASC),
    CONSTRAINT [FK_Booking_Customer] FOREIGN KEY ([CustomerID]) REFERENCES [dbo].[Customer] ([CustomerID])
);

This is in Visual Studio 13, using SQL Server.

How can I get the DATE field to dd/MM/yyyy format?

I tried putting
Code:
SELECT convert(varchar,BookingDate, 103) AS DATE,
but this never worked either.
 

diaspora

Member
I managed to get auth.pl to work in IE, but I've hit a snag, probably a logic error that I'm missing.

Code:
#!/usr/bin/perl

use CGI qw( :standard );

$usnm = param("controlName1");
$pass = param("controlName2");
$postBack = param("postBack");
$break = "<br></br>";

print "Content-type: text/html\n\n";

print "<html>";
print "<head><title>auth.pl</title></head>";
print "<body>";
print "<BR><BR>";
unless ($usnm eq "username" && $pass eq "password") {
	print "You submitted username";
	print "<form name='auth' action='auth.pl' method='post'>";
	print "Username:    <input type='text' name='username'>";
	print "<BR><BR>";
	print "Password:    <input type='password' name='password'>";
	print "<BR><BR>";
	print "<input type='submit' value='Submit'>";

	if (postBack > 0) {
		print "Error";
	}

	print "<input type='hidden' name='postBack' value='1'>";
	print "</form>";
}

else {
	print "<form method='post' action='viewprofile.cgi' name='auth'>";

	print "Username: ";
	print "<input type='text' name='usnm'></intput>";
	print $break;

	print "First Name: ";
	print "<input type='text' name='firstname'></input>";
	print $break;

	print "Surname: ";
	print "<input type='text' name='surname'></input>";
	print $break;

	print "Date of birth: ";
	print "<input type='text' name='dob'></input>";
	print $break;

	print "Country: ";
	print "<select>";
		print "<option value='can'>Canada</option>";
		print "<option value='murica'>United States</option>";
		print "<option value='mex'>Mexico</option>";
	print "</select>";
	print $break;
	
	print "Street Address: ";
	print "<input type='text' name='addr'></input>";
	print $break;
	
	print "Town/ City: ";
	print "<input type='text' name='city'></input>";
	print $break;

	print "Province/ State: ";
	print "<input type='text' name='prv'></input>";
	print $break;

	print "Postal Code: ";
	print "<input type='text' name='postal'></input>";
	print $break;

	print "Home Phone: ";
	print "<input type='text' name='home'></input>";
	print $break;

	print "Mobile Phone: ";
	print "<input type='text' name='mobile'></input>";
	print $break;

	print "E-mail: ";
	print "<input type='email' name='email'></input>";
	print $break;

	print "About: ";
	print "<textarea rows='5' cols='50' name='about'></textarea>";
	print $break;

	print "Upload Image: ";
	print "input type='file' name='pic'></input>";
	print $break;
	
	print "<input type='submit' value='Submit' formaction='viewprofile.cgi'></input>";
	print "<input type='reset' value='Clear'></input>";
	print "</form>";
}
print "</body>";
print "</html>";

Basically, when I enter the correct username and password (being "username" and "password" respectively, the page won't load the content contained in the else statement, it just refreshes the current page.
 
Try printing the variables $usnm and $pass and sandwich them between <p> tags so you can see right on the page if they're being passed through when you submit the HTML form.

Fairly standard debugging here. Make sure what you expect to happen is exactly what you see happening.
 
Top Bottom