Jump to content

Please help with a coding problem, making a picture viewer!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
Hey everyone, I'm new to codecall, and I hate to say it but also new to programming, though I do also belong to another C++ Tutorial Forum and have for the better part of a year.

Anyways, I just downloaded VBE2010 and it's a little different than the 2008 version I used a couple months ago (I haven't done any kind of programming in a couple months) but I do like it though I think it'll take some getting used to.

But I decided to read the tutorial on making a picture viewer (for anyone that uses VB2010 knows there's a tut in there on it)

My problem is an error in the code I can't figure out and I was hoping someone could help me...

This is the code that makes a "show picture" button in my program:

Public Class Form1

Private Sub showButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showButton.Click

'Show the Open File Dialog. If the user clicks OK, load the picture that the user chose.

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then PictureBox1.Load(OpenFileDialog1.FileName)

End If

End Sub

When I build it I get an error message that says:


Error 1 'End If' must be preceded by a matching 'If'. C:\Users\Michael\documents\Form1.vb 6 9 Picture Viewer

However, in the tutorial it says that's how my code should look...Exactly how I have it.

Does anyone know how to help me?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
I'm not a vb coder, I apologize but I speculate that if you have the "Then" portion on the same line, such as your:
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then  PictureBox1.Load(OpenFileDialog1.FileName)
Then the End If is not needed. Looking at the format of IF statements in that language, it looks like you'll need to structure it like this if you want your sample to work:
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then 
    PictureBox1.Load(OpenFileDialog1.FileName)
End If

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
So in VB the way you structure your lines of code can in a sense "make or break" your build?

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,086 posts
Doesn't Visual studio automatically intend everything? I would be unable to write the code as you did because it auto formats it.

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts

RuneNova91 said:

So in VB the way you structure your lines of code can in a sense "make or break" your build?

It seems so, I mean vb doesn't terminate lines by semicolons, look at python, it does similar things and relies on formatting. It helps people code by abstraction better, so to speak.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
RuneNova91

RuneNova91

    Learning Programmer

  • Members
  • PipPipPip
  • 74 posts
I apologize but I forgot the format haha. I don't think I copied and pasted it exactly as it was, I think I fixed it because I'm so used to Visual C++ instead (which I didn't realize VBE is different than VC++) so I installed Visual C++ instead but thanks guys