🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.basic.visual
5 messages
5 total messages Started by Lasse Madsen Thu, 07 Dec 2000 18:03
HELP ! ! ! simple Visual Basic code ???
#280
Author: Lasse Madsen
Date: Thu, 07 Dec 2000 18:03
55 lines
3197 bytes
Hi there im making a small resistor color code calculator based on a slider
(SRa) and 4 (shapes a,b,c and d) the shapes is placed like this |a|b|c|d|
after eatch other to symbolise a resistor. what i want is:

make my slider code control the colors of the 4 shapes (a,b,c,d,)
Below is the colour code a resistor can have and which the 4 shapes should
be assigned

Black = &H0&
Brown = &H4080&
Red = &HFF&
Orange = &H80FF&
Yellow = &HFFFF&
Green = &HC000&
Blue = &HFF0000
Purple = &HC000C0
Gray = &H808080
White = &HFFFFFF

Below you see what each colour represents in decimal values
Black = 0
Brown = 1
Red = 2
Orange 3
Yellow = 4
Green =  5
Blue =  6
Purple =7
Gray =8
White ==9

A resistor value is determined like this:
220 Ohms = 2 - 2 - 0 (first and second digit and third value) but when
converted to color code its like this
2 - 2 - 0 =
Red - Red (2 - 2)
the 0 determins how many zeros that is after the 2 digits (in this case 2-2)
and the color code will be RED - RED - BROWN (brown because because you need
1 zero after 2-2 to make 220 !)

If SRa.Value = 3 Then TRa.Text = "220" & " ohms"    / this should be 2-2-1
Red-Red-Black
If SRa.Value = 4 Then TRa.Text = "270" & " ohms"   /this should be 2-7-1
Red-Purple-Brown


How can i do this ???
--

-------------------------
Electronics Student
Lasse Madsen
H�jrupsvej 52, 2.m.f.
9900 Frederikshavn
Denmark
Re: HELP ! ! ! simple Visual Basic code ???
#276
Author: Nj�l Fisketj�n
Date: Thu, 07 Dec 2000 00:00
78 lines
3783 bytes
On Thu, 7 Dec 2000 19:03:46 +0100, "Lasse Madsen"
<Lasse.Madsen@Elektronik.dk> wrote:

>Hi there im making a small resistor color code calculator based on a slider
>(SRa) and 4 (shapes a,b,c and d) the shapes is placed like this |a|b|c|d|
>after eatch other to symbolise a resistor. what i want is:
>
>make my slider code control the colors of the 4 shapes (a,b,c,d,)
>Below is the colour code a resistor can have and which the 4 shapes should
>be assigned
>
>Black = &H0&
>Brown = &H4080&
>Red = &HFF&
>Orange = &H80FF&
>Yellow = &HFFFF&
>Green = &HC000&
>Blue = &HFF0000
>Purple = &HC000C0
>Gray = &H808080
>White = &HFFFFFF
>
>Below you see what each colour represents in decimal values
>Black = 0
>Brown = 1
>Red = 2
>Orange 3
>Yellow = 4
>Green =  5
>Blue =  6
>Purple =7
>Gray =8
>White ==9
>
>A resistor value is determined like this:
>220 Ohms = 2 - 2 - 0 (first and second digit and third value) but when
>converted to color code its like this
>2 - 2 - 0 =
>Red - Red (2 - 2)
>the 0 determins how many zeros that is after the 2 digits (in this case 2-2)
>and the color code will be RED - RED - BROWN (brown because because you need
>1 zero after 2-2 to make 220 !)
>
>If SRa.Value = 3 Then TRa.Text = "220" & " ohms"    / this should be 2-2-1
>Red-Red-Black
>If SRa.Value = 4 Then TRa.Text = "270" & " ohms"   /this should be 2-7-1
>Red-Purple-Brown
>

I don't understand the concept of changing the ending 0 to 1, but apart
from that here's some code that might help:

I've put a slider on my form together with 4 shapes, and I've set the
FillStyle property of the shapes to Solid.

Private Sub Slider1_Change()
  Dim i As Integer
  Dim ColorCode As Variant
  Dim cc(9) As Long
  Dim strValue As String
  
  i = 0
  For Each ColorCode In Array(&H0&, &H4080&, &HFF&, &H80FF&, &HFFFF&,
    &HC000&, &HFF0000, &HC000C0, &H808080, &HFFFFFF)
    cc(i) = ColorCode
    i = i + 1
  Next
  
  strValue = Trim$(Str$(Slider1.Value))
  For i = 0 To Len(strValue) - 1
    If i > Shape1.UBound Then Exit For
    Shape1(i).FillColor = cc(Val(Mid$(strValue, i + 1, 1)))
    Shape1(i).Visible = True
  Next
  For i = Len(strValue) To Shape1.UBound
    Shape1(i).Visible = False
  Next
End Sub
Re: HELP ! ! ! simple Visual Basic code ???
#277
Author: BKD
Date: Thu, 07 Dec 2000 00:00
108 lines
4272 bytes
Assuming the following declarations:

Dim strResValue As String, iFirstDigit As Integer, iSecondDigit As Integer,
iNumDigits as Integer

First, decode the slider:

    Select Case SRa.Value
        Case 3
            strResValue = 220
        Case 4
            strResValue = 270
        'add more cases as required
    End Select

Then get the first and second digits:

    iFirstDigit = Cint(Left$(strResValue,1)
    iSecondDigit = Cint(Mid$(strResValue,2,1)

Next get the number of zeros needed:

    iNumDigits = Len(strResValue) -2

Now apply them to the shapes with code like this:

    Select Case iFirstDigit
        Case 0
            ShapeA.BackColor = &H0&
        Case 1
            ShapeA.BackColor = &H4080&
        'and so on
    End Select

You could make it more efficient with enums and such like that, but this is
the basic gist as I would approach it.  Note that if you use tight tolerance
or low value resistors you will need to accomodate the decimal point in the
decoding statements.  Also this code assumes all values are in ohms, not K
or M.

Good Luck.

Brian-



Lasse Madsen <Lasse.Madsen@Elektronik.dk> wrote in message
news:90oika$143u$1@news.cybercity.dk...
> Hi there im making a small resistor color code calculator based on a
slider
> (SRa) and 4 (shapes a,b,c and d) the shapes is placed like this |a|b|c|d|
> after eatch other to symbolise a resistor. what i want is:
>
> make my slider code control the colors of the 4 shapes (a,b,c,d,)
> Below is the colour code a resistor can have and which the 4 shapes should
> be assigned
>
> Black = &H0&
> Brown = &H4080&
> Red = &HFF&
> Orange = &H80FF&
> Yellow = &HFFFF&
> Green = &HC000&
> Blue = &HFF0000
> Purple = &HC000C0
> Gray = &H808080
> White = &HFFFFFF
>
> Below you see what each colour represents in decimal values
> Black = 0
> Brown = 1
> Red = 2
> Orange 3
> Yellow = 4
> Green =  5
> Blue =  6
> Purple =7
> Gray =8
> White ==9
>
> A resistor value is determined like this:
> 220 Ohms = 2 - 2 - 0 (first and second digit and third value) but when
> converted to color code its like this
> 2 - 2 - 0 =
> Red - Red (2 - 2)
> the 0 determins how many zeros that is after the 2 digits (in this case
2-2)
> and the color code will be RED - RED - BROWN (brown because because you
need
> 1 zero after 2-2 to make 220 !)
>
> If SRa.Value = 3 Then TRa.Text = "220" & " ohms"    / this should be 2-2-1
> Red-Red-Black
> If SRa.Value = 4 Then TRa.Text = "270" & " ohms"   /this should be 2-7-1
> Red-Purple-Brown
>
>
> How can i do this ???
> --
>
> -------------------------
> Electronics Student
> Lasse Madsen
> H�jrupsvej 52, 2.m.f.
> 9900 Frederikshavn
> Denmark
>
>
Re: HELP ! ! ! simple Visual Basic code ???
#281
Author: ton
Date: Fri, 08 Dec 2000 21:45
106 lines
4400 bytes
Public x As Integer
Public va As String

Private Sub Form_Load()
x = 0
End Sub

Private Sub Text3_Click(Index As Integer)
nr = Text3(Index).Index
If x = 3 Then
For t = 0 To 2: Text1(t).BackColor = &H80000005: Next
x = 0
va = ""
End If
Text1(x).BackColor = Text3(nr).BackColor
x = x + 1
Select Case x
Case 1
va = CStr(nr) & va
Case 2
va = va & CStr(nr)
Case 3
    Select Case nr
    Case 0
    va = va & "0 ohm"
    Case 1
    va = va & "0 ohm"
    Case 2
    va = va & "00 ohm"
    Case 3
    va = va & " K ohm"
    Case 4
    va = va & "0 Kohm"
    Case 5
    va = va & " M ohm"
    End Select
End Select
Text2.Text = va
End Sub
The form consists of a textbox 'text2.text', 3 small(1 character) textboxes
text1(0).text etc and 10 small textboxes text3(0..9) with the colors you
describe as backcolor.
Nice idea, works simple. I'll send you the form if you want.
regards, ton
Lasse Madsen <Lasse.Madsen@Elektronik.dk> schreef in berichtnieuws
90oika$143u$1@news.cybercity.dk...
> Hi there im making a small resistor color code calculator based on a
slider
> (SRa) and 4 (shapes a,b,c and d) the shapes is placed like this |a|b|c|d|
> after eatch other to symbolise a resistor. what i want is:
>
> make my slider code control the colors of the 4 shapes (a,b,c,d,)
> Below is the colour code a resistor can have and which the 4 shapes should
> be assigned
>
> Black = &H0&
> Brown = &H4080&
> Red = &HFF&
> Orange = &H80FF&
> Yellow = &HFFFF&
> Green = &HC000&
> Blue = &HFF0000
> Purple = &HC000C0
> Gray = &H808080
> White = &HFFFFFF
>
> Below you see what each colour represents in decimal values
> Black = 0
> Brown = 1
> Red = 2
> Orange 3
> Yellow = 4
> Green =  5
> Blue =  6
> Purple =7
> Gray =8
> White ==9
>
> A resistor value is determined like this:
> 220 Ohms = 2 - 2 - 0 (first and second digit and third value) but when
> converted to color code its like this
> 2 - 2 - 0 =
> Red - Red (2 - 2)
> the 0 determins how many zeros that is after the 2 digits (in this case
2-2)
> and the color code will be RED - RED - BROWN (brown because because you
need
> 1 zero after 2-2 to make 220 !)
>
> If SRa.Value = 3 Then TRa.Text = "220" & " ohms"    / this should be 2-2-1
> Red-Red-Black
> If SRa.Value = 4 Then TRa.Text = "270" & " ohms"   /this should be 2-7-1
> Red-Purple-Brown
>
>
> How can i do this ???
> --
>
> -------------------------
> Electronics Student
> Lasse Madsen
> H�jrupsvej 52, 2.m.f.
> 9900 Frederikshavn
> Denmark
>
>
Re: HELP ! ! ! simple Visual Basic code ???
#282
Author: Lasse Madsen
Date: Mon, 11 Dec 2000 02:03
126 lines
5027 bytes
Dear Ton

I would wery much appriciate the form project if you will send it to me, If
its possible i would like 2 independent resistor calculators on that one
form, Cause the project that im making requres 2 independent resistor values
to be shown in colour code

Thanks alot
Regards
Lasse Madsen
Denmark

"ton" <zoetermeer@xs4all.nl> skrev i en meddelelse
news:90rkbe$i4k$1@news1.xs4all.nl...
> Public x As Integer
> Public va As String
>
> Private Sub Form_Load()
> x = 0
> End Sub
>
> Private Sub Text3_Click(Index As Integer)
> nr = Text3(Index).Index
> If x = 3 Then
> For t = 0 To 2: Text1(t).BackColor = &H80000005: Next
> x = 0
> va = ""
> End If
> Text1(x).BackColor = Text3(nr).BackColor
> x = x + 1
> Select Case x
> Case 1
> va = CStr(nr) & va
> Case 2
> va = va & CStr(nr)
> Case 3
>     Select Case nr
>     Case 0
>     va = va & "0 ohm"
>     Case 1
>     va = va & "0 ohm"
>     Case 2
>     va = va & "00 ohm"
>     Case 3
>     va = va & " K ohm"
>     Case 4
>     va = va & "0 Kohm"
>     Case 5
>     va = va & " M ohm"
>     End Select
> End Select
> Text2.Text = va
> End Sub
> The form consists of a textbox 'text2.text', 3 small(1 character)
textboxes
> text1(0).text etc and 10 small textboxes text3(0..9) with the colors you
> describe as backcolor.
> Nice idea, works simple. I'll send you the form if you want.
> regards, ton
> Lasse Madsen <Lasse.Madsen@Elektronik.dk> schreef in berichtnieuws
> 90oika$143u$1@news.cybercity.dk...
> > Hi there im making a small resistor color code calculator based on a
> slider
> > (SRa) and 4 (shapes a,b,c and d) the shapes is placed like this
|a|b|c|d|
> > after eatch other to symbolise a resistor. what i want is:
> >
> > make my slider code control the colors of the 4 shapes (a,b,c,d,)
> > Below is the colour code a resistor can have and which the 4 shapes
should
> > be assigned
> >
> > Black = &H0&
> > Brown = &H4080&
> > Red = &HFF&
> > Orange = &H80FF&
> > Yellow = &HFFFF&
> > Green = &HC000&
> > Blue = &HFF0000
> > Purple = &HC000C0
> > Gray = &H808080
> > White = &HFFFFFF
> >
> > Below you see what each colour represents in decimal values
> > Black = 0
> > Brown = 1
> > Red = 2
> > Orange 3
> > Yellow = 4
> > Green =  5
> > Blue =  6
> > Purple =7
> > Gray =8
> > White ==9
> >
> > A resistor value is determined like this:
> > 220 Ohms = 2 - 2 - 0 (first and second digit and third value) but when
> > converted to color code its like this
> > 2 - 2 - 0 =
> > Red - Red (2 - 2)
> > the 0 determins how many zeros that is after the 2 digits (in this case
> 2-2)
> > and the color code will be RED - RED - BROWN (brown because because you
> need
> > 1 zero after 2-2 to make 220 !)
> >
> > If SRa.Value = 3 Then TRa.Text = "220" & " ohms"    / this should be
2-2-1
> > Red-Red-Black
> > If SRa.Value = 4 Then TRa.Text = "270" & " ohms"   /this should be 2-7-1
> > Red-Purple-Brown
> >
> >
> > How can i do this ???
> > --
> >
> > -------------------------
> > Electronics Student
> > Lasse Madsen
> > H�jrupsvej 52, 2.m.f.
> > 9900 Frederikshavn
> > Denmark
> >
> >
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads