Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,068 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,785 people online right now. Registration is fast and FREE... Join Now!




Is it actually possible to do this?

 
Reply to this topicStart new topic

Is it actually possible to do this?, Working in (free) Visual Basic 2008 Express Edition, for AQAs CPT3 pra

Sonyaswan
26 Feb, 2008 - 01:45 PM
Post #1

New D.I.C Head
*

Joined: 26 Feb, 2008
Posts: 4


My Contributions
I'm trying to do the Peter's Petrol Pumps coursework set by the AQA board for this year's CPT3 Project. So far I have worked out everything apart from the LCD display, and I am quite far ahead of everyone else in my class. Being ahead of everyone else, it is almost impossible to ask my teacher for help as he says I don't need it until everyone else is at my level. I have three problems:

1) I have 91 Pictureboxes as my LCDs (2 pictures, one for horizontal, one for vertical). The coding seems to work, but then the LCDs don't actually change, so I guess that would be my biggest problem...

2) My Pictureboxes are named "PB1A", "PB2A", "PB1F", "PB2F" etc, I was trying to see if I could create a For...Next Loop to refer to each of them, instead of having to individually go through them as in the example below:

CODE

        LCD(7, 0) = PB1A.Visible
        LCD(8, 0) = PB1N.Visible
        LCD(9, 0) = PB1C.Visible
        LCD(10, 0) = PB1D.Visible
        LCD(10, 0) = PB1E.Visible
        etc


I would rather have the 31 lines (or similar) as shown below, or have another simpler way of doing it, than having 91 lines like those in the above coding. I was wondering if it was actually possible to do something like this, and if so, how, because this coding doesn't work... ^^;

CODE

    Dim LCD(12, 6) As Boolean
    Dim LCDSubstring(11) As Integer
    Dim X, Y As Integer
    Dim Z As String
    Dim IndividualLCD As String

    Sub LCDSub()
        For X = 0 To 11
            For Y = 0 To 6
                If X = 0 Then
                    Z = "F"
                ElseIf X = 1 Then
                    Z = "G"
                ElseIf X = 2 Then
                    Z = "H"
                ElseIf X = 3 Then
                    Z = "J"
                ElseIf X = 4 Then
                    Z = "K"
                ElseIf X = 5 Then
                    Z = "L"
                ElseIf X = 6 Then
                    Z = "M"
                ElseIf X = 7 Then
                    Z = "A"
                ElseIf X = 8 Then
                    Z = "N"
                ElseIf X = 9 Then
                    Z = "C"
                ElseIf X = 10 Then
                    Z = "D"
                ElseIf X = 11 Then
                    Z = "E"
                End If
                IndividualLCD = "PB" & (Y + 1) & Z
                LCD(X, Y) = IndividualLCD.Visible
            Next
        Next


        LCDSubstring(0) = lblATP.Text.Substring(0)
        LCDSubstring(1) = lblATP.Text.Substring(1)
        LCDSubstring(2) = lblATP.Text.Substring(2)
        LCDSubstring(3) = lblATP.Text.Substring(4)
        LCDSubstring(4) = lblATP.Text.Substring(5)
        LCDSubstring(5) = lblLitres.Text.Substring(0)
        LCDSubstring(6) = lblLitres.Text.Substring(1)
        LCDSubstring(7) = lblLitres.Text.Substring(3)
        LCDSubstring(8) = lblPpL.Text.Substring(0)
        LCDSubstring(9) = lblPpL.Text.Substring(1)
        LCDSubstring(10) = lblPpL.Text.Substring(2)
        LCDSubstring(11) = lblPpL.Text.Substring(4)

        For Me.Z = 0 To 11
            If LCDSubstring(Z) = 0 Then
                For Me.Y = 0 To 6
                    If Me.Y = 3 Then
                        LCD(Z, Y) = False
                    Else
                        LCD(Z, Y) = True
                    End If
                Next
            ElseIf LCDSubstring(Z) = 1 Then
                For Me.Y = 0 To 6
                    If Me.Y = 2 Or Me.Y = 5 Then
                        LCD(Z, Y) = True
                    Else
                        LCD(Z, Y) = False
                    End If
                Next
            ElseIf LCDSubstring(Z) = 2 Then
                For Me.Y = 0 To 6
                    If Me.Y = 1 Or Me.Y = 5 Then
                        LCD(Z, Y) = False
                    Else
                        LCD(Z, Y) = True
                    End If
                Next
            ElseIf LCDSubstring(Z) = 3 Then
                For Me.Y = 0 To 6
                    If Me.Y = 1 Or Me.Y = 4 Then
                        LCD(Z, Y) = False
                    Else
                        LCD(Z, Y) = True
                    End If
                Next
            ElseIf LCDSubstring(Z) = 4 Then
                For Me.Y = 0 To 6
                    If Me.Y = 0 Or Me.Y = 4 Or Me.Y = 6 Then
                        LCD(Z, Y) = False
                    Else
                        LCD(Z, Y) = True
                    End If
                Next
            ElseIf LCDSubstring(Z) = 5 Then
                For Me.Y = 0 To 6
                    If Me.Y = 2 Or Me.Y = 4 Then
                        LCD(Z, Y) = False
                    Else
                        LCD(Z, Y) = True
                    End If
                Next
            ElseIf LCDSubstring(Z) = 6 Then
                For Me.Y = 0 To 6
                    If Me.Y = 2 Then
                        LCD(Z, Y) = False
                    Else
                        LCD(Z, Y) = True
                    End If
                Next
            ElseIf LCDSubstring(Z) = 7 Then
                For Me.Y = 0 To 6
                    If Me.Y = 0 Or Me.Y = 2 Or Me.Y = 5 Then
                        LCD(Z, Y) = True
                    Else
                        LCD(Z, Y) = False
                    End If
                Next
            ElseIf LCDSubstring(Z) = 8 Then
                For Me.Y = 0 To 6
                    LCD(Z, Y) = True
                Next Y
            ElseIf LCDSubstring(Z) = 9 Then
                For Me.Y = 0 To 6
                    If Me.Y = 5 Then
                        LCD(Z, Y) = False
                    Else
                        LCD(Z, Y) = True
                    End If
                Next
            End If
        Next Z
    End Sub


3) Our college is using an earlier version of VB than I am on my computer at home... is there a way that I can save the project in the earlier version's format? otherwise I can't actually open my project at college, which kind of defeats the puropse of it....

Thanks for reading, and thanks in advance for any help given ^^

-Sonya

This post has been edited by Sonyaswan: 26 Feb, 2008 - 02:30 PM
User is offlineProfile CardPM
+Quote Post

GetThatFooty
RE: Is It Actually Possible To Do This?
26 Feb, 2008 - 01:56 PM
Post #2

New D.I.C Head
*

Joined: 2 Feb, 2008
Posts: 39


My Contributions
I can't help with your problem as I am still learning like you. However, I have a trial copy of Visual Studio 2005 that i never used from school if you want it. It's good for 90 days which should get you through the semester.
User is offlineProfile CardPM
+Quote Post

Sonyaswan
RE: Is It Actually Possible To Do This?
26 Feb, 2008 - 02:07 PM
Post #3

New D.I.C Head
*

Joined: 26 Feb, 2008
Posts: 4


My Contributions
QUOTE(GetThatFooty @ 26 Feb, 2008 - 02:56 PM) *

I can't help with your problem as I am still learning like you. However, I have a trial copy of Visual Studio 2005 that i never used from school if you want it. It's good for 90 days which should get you through the semester.

I've already created the project in the Visual Studio 2008 version I have... but I guess being able to copy everything over would be better than having to create it all from scratch again, so I might take you up on your offer XD
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Is It Actually Possible To Do This?
26 Feb, 2008 - 04:44 PM
Post #4

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,282



Thanked: 136 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
So you have a whole mess of PictureBox objects on your form and you're having a hard time manipulating them, because they're just a bunch of names?

First, this kind of thing just isn't going to work, I'm afraid:
CODE

LCD(X, Y) = "PB1A".Visible


Currently, it looks like you've loaded the current Visible values into your array. You're manipulating those values, but the picture box source doesn't know that. Am I correct that you actually what those boolean values pushed back to the PictureBoxes? One choice would be to periodically refresh the actual object based on your booleans.

A more straight forward solution would be an array of PicturBox. e.g.

CODE

Dim LCD(12, 6) As PictureBox
Sub InitLCD()
    LCD(7, 0) = PB1A
    LCD(8, 0) = PB1N
    LCD(9, 0) = PB1C
    ...
End Sub


Ok you still have the initial pain of setup, but you need never do it again. wink2.gif

Your logic loop seems a little odd to me. Also, LCDSubstring(0) would be a string?

Here's another attack:

CODE

LCDSub = LCDSubstring(Z)
For Y = 0 To 6
    If LCDSub = "0" Then
        LCD(Z, Y).Visible = (Y<>3)
    ElseIf LCDSub = "1" Then
        LCD(Z, Y).Visible = (Y=2) Or (Y=5)
    ElseIf LCDSub = "2" Then
        LCD(Z, Y).Visible = Not ((Y=1) Or (Y=5))
...


Hope this helps.

User is offlineProfile CardPM
+Quote Post

Nayana
RE: Is It Actually Possible To Do This?
26 Feb, 2008 - 05:06 PM
Post #5

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
Why don't you just use ONE picturebox? You can handle it's paint event and draw the LCD straight from an array in there. Use the FillRectangle method on the Graphics object passed to you in the event.
User is offlineProfile CardPM
+Quote Post

Sonyaswan
RE: Is It Actually Possible To Do This?
27 Feb, 2008 - 09:14 AM
Post #6

New D.I.C Head
*

Joined: 26 Feb, 2008
Posts: 4


My Contributions
@baavgai
lol yeah, the substring would be a string! Its amazing how immersed you can become in your own coding and not realise silly things like that...

and thanks for your help with the If statement! I didn't know there was a way to do that on one line per statement XD as I said I'm just a college student learning this as part of my course, so they don't bother to teach us things like that -.-

@Nayana
I haven't worked with pictureboxes before, so I didn't know I could do that... sorry for the n00bish question but what is a paint event?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 10:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month