Re: VB project

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 02/24/04


Date: Tue, 24 Feb 2004 11:33:37 -0600


"waylander_jm" <waylander_jm@hotmail.com> wrote
> Hello all, I have a friend who is taking a vb class and she was
> stumped on the following assignement.

Generally I advise students to consult their instructor. That
lets the instructor know that student is having trouble, and if
several students have the same trouble then the lesson plan may
need adjustment (eg, the instructor will know that too).

> write a program that given a 7 digit number, writes to a file every
> possible seven-letter word combination corresponding to that number.

> I created a form with 7 textboxes that will be used to enter numbers.

FWIW:
That is not very user friendly. It is not common to enter a phone
number in 7 different boxes...

> I coded it so it will not allow the user to enter a 0 or 1. I used a
> two dimensional array to hold the digits corresponding alpha numeric
> letters but I am stuck as how to output the combinations. The code is
> below.

See if the code below makes sense to you. If you don't understand
it, you can't really explain it, so post back if you need help, before
going to your friend. (That and you'll look better if you don't have to
say, 'wait and I'll go ask the guy who wrote it' ;-)

I would sugget you let your friend figure out how to convert the
code so that it can write to a file. That is also an important part
of programming, and may be part of the reason for the problem.

Have fun!
LFS

Option Explicit

Private Sub Form_Load()
  ' 29 - a quick test of lower & upper bounds
  PermutatePhoneWords "29"
End Sub

Private Sub PermutatePhoneWords(Number As String)
Dim num() As Byte
Dim cnt() As Byte
Dim n&, c&, ub as long
Dim prm As String
Const ltr = "-----ABCDEFGHIJKLMNOPRSTUVWXYZ"

  ' Verify input
  If Number Like "*[!2-9]*" Then
    Debug.Print "BAD INPUT: "; Number
    Exit Sub
  End If

  ' Make room
  ub = Len(Number)
  ReDim num(1 To ub)
  ReDim cnt(1 To ub)

  ' Initialize arrays
  For n = 1 To ub
    num(n) = Val(Mid$(Number, n, 1))
    cnt(n) = 0
  Next

  Do
    ' Get current permutation
    ' num() has major offset (group) cnt() has minor offset (letter)
    prm = Space$(ub)
    For n = 1 To ub
      Mid(prm, n, 1) = Mid(ltr, num(n) * 3 + cnt(n), 1)
    Next

    ' save to file
    Debug.Print prm

    ' Increment counters (like odometer rollover)
    c = ub
    cnt(c) = cnt(c) + 1
    Do While cnt(c) > 2
      cnt(c) = 0
      c = c - 1
      If c = 0 Then Exit Sub ' Done
      cnt(c) = cnt(c) + 1
    Loop

  Loop

End Sub



Relevant Pages

  • Re: Friend Property ques
    ... > I'm surprised to see that a property procedure declared with Friend ... > Friend Property Let MatchName(sData As String) ... > Private Sub LoadListBox() ... > Dim sblkname As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Selecting Each Row and Creating a New File
    ... Sub AssignRow() ... Dim PersonalInfo As Range ... Dim Header As Range ... I am trying to build an attendance list, where students go down the ...
    (microsoft.public.excel.programming)
  • Re: VB project
    ... Something that you can mention to your friend is to never do this: ... > End Sub ... > Dim flhndl As Integer ... > Private Sub Drive1_Change ...
    (microsoft.public.vb.general.discussion)
  • Re: Heres a Story You Will Never See On Fox News
    ... >>college assignments. ... >>plagiarized writing by the students, who must submit their work as computer ... >>in years 1 through 3 was a complete mystery. ... When I sub for the math instructors, ...
    (rec.boats)
  • RE: How to set count in form with a maximum that cant be exceeded...
    ... Private Sub Form_Current ... Set recSet = Me.RecordsetClone ... indicating the maximum capacity. ... > I have a sub form that calculates the number of students enrolled in a class. ...
    (microsoft.public.access.forms)