Author Topic: Is anyone familiar with visual basic? I need help  (Read 815 times)

Offline hitech

  • Administrator
  • Administrator
  • *****
  • Posts: 12425
      • http://www.hitechcreations.com
Re: Is anyone familiar with visual basic? I need help
« Reply #15 on: April 02, 2014, 09:49:24 AM »
Im Not sure of exact VB syntacs it has been a long time but the idea is this

int dim(4,13) Cards;


int HandIs4OfAKind(int dim(4,13)Cards)
{
int Suite,Number;
   for Number = 1 to 13
    if(Cards[1][Number] = 1 and Cards[2][Number] = 1 and Cards[3][Number] = 1 and Cards[4][Number] = 1)
      return 1

   return 0

}

Offline BluBerry

  • Persona Non Grata
  • Silver Member
  • ****
  • Posts: 1937
Re: Is anyone familiar with visual basic? I need help
« Reply #16 on: April 02, 2014, 10:53:11 AM »
aisdbvlqejfnbvjqkenrv 4[32452345]  12nsk.//123


hope this helps.  :salute

Offline ImADot

  • Platinum Member
  • ******
  • Posts: 6215
Re: Is anyone familiar with visual basic? I need help
« Reply #17 on: April 02, 2014, 11:21:08 AM »
Not that I like doing other people's homework, but I'm a bit bored at work today.  ;)

This snippet of code it attached to the Click event of a button, and for testing I coded the test to simulate someone entering Ace of Diamonds:

Dim arrayCards(3, 12) As Integer
Dim Suit As String
Dim Face As String

'Pre-populate array with all zeros
For s = 0 To 3
   For f = 0 To 12
      arrayCards(s, f) = 0
   Next
Next

'Simulate values from form textbox
Suit = "D"
Face = "1"

'Set the corresponding array value to 1
Select Case Suit
   Case "C"
      arrayCards(0, Face - 1) = 1
   Case "D"
      arrayCards(1, Face - 1) = 1
   Case "H"
      arrayCards(2, Face - 1) = 1
   Case "S"
      arrayCards(3, Face - 1) = 1
End Select


This should result in your two-dimensional array filled with zeros except for the element for the Ace of Diamonds. You should be able to use this as a template for gathering all the values from all the textboxes on your form (based on the picture of the form in your previous post).

Enjoy.
My Current Rig:
GigaByte GA-X99-UD4 Mobo w/ 16Gb RAM
Intel i7 5820k, Win7 64-bit
NVidia GTX 970 4Gb ACX 2.0
Track IR, CH Fighterstick, CH Pro Throttle, CH Pro Pedals

Offline SilverZ06

  • Silver Member
  • ****
  • Posts: 1727
Re: Is anyone familiar with visual basic? I need help
« Reply #18 on: April 02, 2014, 11:21:42 AM »
Im Not sure of exact VB syntacs it has been a long time but the idea is this

int dim(4,13) Cards;


int HandIs4OfAKind(int dim(4,13)Cards)
{
int Suite,Number;
   for Number = 1 to 13
    if(Cards[1][Number] = 1 and Cards[2][Number] = 1 and Cards[3][Number] = 1 and Cards[4][Number] = 1)
      return 1

   return 0

}

Thank you Hitech! This will definitely help.

Offline wpeters

  • Silver Member
  • ****
  • Posts: 1647
Re: Is anyone familiar with visual basic? I need help
« Reply #19 on: April 02, 2014, 11:30:42 AM »
Man with all you guys talking gibbirish makes me want to learn it to.   What do I need to get and go to learn coding.  I think it might be come a new hobby when I am bored of flying.
LtCondor
          The Damned
Fighter pilots are either high, or in the process of getting high.🙊
The difference between Dweebs and non dweebs... Dweebs have kills

Offline SilverZ06

  • Silver Member
  • ****
  • Posts: 1727
Re: Is anyone familiar with visual basic? I need help
« Reply #20 on: April 02, 2014, 11:32:33 AM »
Not that I like doing other people's homework, but I'm a bit bored at work today.  ;)

This snippet of code it attached to the Click event of a button, and for testing I coded the test to simulate someone entering Ace of Diamonds:

Dim arrayCards(3, 12) As Integer
Dim Suit As String
Dim Face As String

'Pre-populate array with all zeros  'I believe in VB when you declare an array the elements are automatically initialized to 0 (unless initialized to something else obviously).
For s = 0 To 3
   For f = 0 To 12
      arrayCards(s, f) = 0    
   Next
Next


'Simulate values from form textbox
Suit = "D"                                                            'So this is where I am lost. would this be something like: Select Case suit txtCard1Suit.text
Face = "1"                                                                                                                                               Case "C"
                                                                                                                                                                     arrayCards(0,Face-1)=1
  
                                                                                                                                           
                                                                          
'Set the corresponding array value to 1
Select Case Suit
   Case "C"
      arrayCards(0, Face - 1) = 1
   Case "D"
      arrayCards(1, Face - 1) = 1
   Case "H"
      arrayCards(2, Face - 1) = 1
   Case "S"
      arrayCards(3, Face - 1) = 1
End Select


This should result in your two-dimensional array filled with zeros except for the element for the Ace of Diamonds. You should be able to use this as a template for gathering all the values from all the textboxes on your form (based on the picture of the form in your previous post).

Enjoy.

Then I would use a For loop for all cards to do the same to populate the array. Thank you so much. This helps tremendously I still have a lot to figure out but this gets me going instead of blankly staring at my screen.

Offline ImADot

  • Platinum Member
  • ******
  • Posts: 6215
Re: Is anyone familiar with visual basic? I need help
« Reply #21 on: April 02, 2014, 12:32:17 PM »
Ok, lesson #2   :D

Build your form and name your textboxes something like "txtCard1", "txtCard2", "txtSuit1", "txtSuit2", etc. and use the Tag property to set the card textboxes to "card". This way, you can loop through all controls and only work with specific textboxes without having to spell out each name. From there, it's just the one loop, each suit textbox name is created to match the card box you're working with, and your array is complete and ready for you to figure out what poker hand it is.

Dim arrayCards(3, 12) As Byte
Dim Suit As String
Dim Face As String
Dim idx As Byte
Dim Suitbox As String

'Loop through all controls on the form
For Each ctl As Control In Me.Controls
   'only grab controls tagged with "card"
   If ctl.Tag = "card" Then
      'get control number (right-most character) from the textbox name so you can get corresponding suit
      idx = ctl.Name.Substring(Len(ctl.Name) - 1)
      Suitbox = "txtSuit" & idx
      'get the values in the text boxes
      Suit = Me.Controls(Suitbox).Text
      Face = ctl.Text

      'Set the corresponding array value to 1
      Select Case UCase(Suit)
         Case "C"
            arrayCards(0, Face - 1) = 1
         Case "D"
            arrayCards(1, Face - 1) = 1
         Case "H"
            arrayCards(2, Face - 1) = 1
         Case "S"
            arrayCards(3, Face - 1) = 1
      End Select

   End If
Next ctl
My Current Rig:
GigaByte GA-X99-UD4 Mobo w/ 16Gb RAM
Intel i7 5820k, Win7 64-bit
NVidia GTX 970 4Gb ACX 2.0
Track IR, CH Fighterstick, CH Pro Throttle, CH Pro Pedals

Offline hitech

  • Administrator
  • Administrator
  • *****
  • Posts: 12425
      • http://www.hitechcreations.com
Re: Is anyone familiar with visual basic? I need help
« Reply #22 on: April 02, 2014, 01:15:00 PM »
I'm curious,do VB array indices start with 0 or 1? If my memory is correct they used to start at 1.

They may have simply changed to it be backwards compatible that dim statement allocates one more then entered so you don't overflow with one based, but can then index from 0 base.

Hence why the example Dim(3,12) would work if zero based is now supported in VB.

I't has been over 20 years since I wrote any VB.

HiTech


Offline Hoplite

  • Nickel Member
  • ***
  • Posts: 427
Re: Is anyone familiar with visual basic? I need help
« Reply #23 on: April 02, 2014, 01:33:04 PM »
Man with all you guys talking gibbirish makes me want to learn it to.   What do I need to get and go to learn coding.  I think it might be come a new hobby when I am bored of flying.

Not a bad place to start....and it's free.

http://www.codecademy.com/

Offline ImADot

  • Platinum Member
  • ******
  • Posts: 6215
Re: Is anyone familiar with visual basic? I need help
« Reply #24 on: April 02, 2014, 01:36:05 PM »
Yep, VB uses base 0 for arrays. For VBA (Visual Basic for Applications) for automating Excel, Access, etc. you can use the statement "Option Base 1" in the code to specify arrays should should at 1 instead of 0.

Quote
In Microsoft Visual Basic 6.0, you can define arrays with the lower bounds and upper bounds set to any integer. You can also use the ReDim statement to reassign a variant as an array.

In Visual Basic .NET, the lower bound for arrays is set to zero to enable interoperability with other languages. Furthermore, you cannot use ReDim unless the variable was previously declared with Dim As Array. The Option Base {0|1} has been removed in Visual Basic .NET because it is no longer required. Although this restricts how you define arrays, it enables you to pass arrays between Visual Basic .NET and any other language in the Microsoft .NET Framework.

« Last Edit: April 02, 2014, 01:40:49 PM by ImADot »
My Current Rig:
GigaByte GA-X99-UD4 Mobo w/ 16Gb RAM
Intel i7 5820k, Win7 64-bit
NVidia GTX 970 4Gb ACX 2.0
Track IR, CH Fighterstick, CH Pro Throttle, CH Pro Pedals

Offline grizz441

  • Platinum Member
  • ******
  • Posts: 7001
Re: Is anyone familiar with visual basic? I need help
« Reply #25 on: April 02, 2014, 10:04:12 PM »
I recall that c++ arrays start at 0 now that you mention it.

Offline Hoplite

  • Nickel Member
  • ***
  • Posts: 427
Re: Is anyone familiar with visual basic? I need help
« Reply #26 on: April 02, 2014, 10:49:13 PM »
I recall that c++ arrays start at 0 now that you mention it.

I think that's correct as well....but its been a LOOONG time since doing anything in C++ for me. 

I am old and befuddled now, 20 years of IT down the crapper.  Pretty soon I'll be old and distrustful of technology like my father. Heck...I don't even get the point of Twitter!  ;)

Offline eagl

  • Platinum Member
  • ******
  • Posts: 6769
Re: Is anyone familiar with visual basic? I need help
« Reply #27 on: April 02, 2014, 11:05:12 PM »
PS this is not a tiny program would be 1 to3 Hours to me


Yea.  I could brute force it with conditionals because I don't have any poker-related pattern recognition shortcuts in my brain.  One trick could be to add up all the columns and rows individually.  A row that equals 5 is a flush.  5 consecutive columns (including wrap-around to account for ace) that equal 1 is a straight. edit - I see that's already been posted by someone else.  In any case, I'd probably start off brute force condition checking for each type of hand, and then look for patterns so I could combine the tests as much as possible.  There's probably at least one test where recursion could result in some tight code, at the expense of readability and boundary checking and wasted time sorting out the logic and exit conditions.

VB had just come out when I went through my comp sci degree program and my school didn't offer any courses in it.  I think they looked at it as a fad and wanted to see if it gained any traction.  Too bad.  Instead of learning VB I got ADA, massively parallel programming, and a handful of other courses that would have been of value if I'd continued my USAF career in the R&D field, but of very little value now.  I guess the parallel programming theory would apply to low level graphics hardware programming, but I don't think most developers dive that deep even with modern GPUs.  The largest computer I had time on was a govt supercomputer and I had access to a 100x100 2D array of independently programmable processors for about a total of 1 hr of compute time.  The architecture had both shared and isolated memory, and each processing node had a very low latency shared memory register with cross-connected adjacent nodes.  I think I used a total of 200 seconds of compute time and never did any optional projects that could have really stretched that computer's capabilities.  Back in 1993...
« Last Edit: April 02, 2014, 11:17:48 PM by eagl »
Everyone I know, goes away, in the end.

Offline Swoop

  • Plutonium Member
  • *******
  • Posts: 9180
Re: Is anyone familiar with visual basic? I need help
« Reply #28 on: April 03, 2014, 02:51:49 AM »
For VBA  you can use the statement "Option Base 1" in the code to specify arrays should should at 1 instead of 0.

I've learned something today. :)

Offline SilverZ06

  • Silver Member
  • ****
  • Posts: 1727
Re: Is anyone familiar with visual basic? I need help
« Reply #29 on: April 03, 2014, 03:30:26 PM »
Ok, lesson #2   :D

Build your form and name your textboxes something like "txtCard1", "txtCard2", "txtSuit1", "txtSuit2", etc. and use the Tag property to set the card textboxes to "card". This way, you can loop through all controls and only work with specific textboxes without having to spell out each name. From there, it's just the one loop, each suit textbox name is created to match the card box you're working with, and your array is complete and ready for you to figure out what poker hand it is.

Dim arrayCards(3, 12) As Byte
Dim Suit As String
Dim Face As String
Dim idx As Byte
Dim Suitbox As String

'Loop through all controls on the form
For Each ctl As Control In Me.Controls
   'only grab controls tagged with "card"
   If ctl.Tag = "card" Then
      'get control number (right-most character) from the textbox name so you can get corresponding suit
      idx = ctl.Name.Substring(Len(ctl.Name) - 1)
      Suitbox = "txtSuit" & idx
      'get the values in the text boxes
      Suit = Me.Controls(Suitbox).Text
      Face = ctl.Text

      'Set the corresponding array value to 1
      Select Case UCase(Suit)
         Case "C"
            arrayCards(0, Face - 1) = 1
         Case "D"
            arrayCards(1, Face - 1) = 1
         Case "H"
            arrayCards(2, Face - 1) = 1
         Case "S"
            arrayCards(3, Face - 1) = 1
      End Select

   End If
Next ctl


This looks great but it is definitely way more advanced than we have gotten so far in this class. I am going to get working on this code tonight or tomorrow night and I'll post what I can come up to get you guys' input/advise. I really do appreciate all of you guys' help. I bet I will learn more in this thread than in this class.