Re: VB project
From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 02/24/04
- Next message: Lance Lee: "Re: How to show a GIF in an ActiveSkin SkinStatic Object?"
- Previous message: Vlad: "Where is value sitting?"
- In reply to: waylander_jm: "VB project"
- Next in thread: Saga: "Re: VB project"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Lance Lee: "Re: How to show a GIF in an ActiveSkin SkinStatic Object?"
- Previous message: Vlad: "Where is value sitting?"
- In reply to: waylander_jm: "VB project"
- Next in thread: Saga: "Re: VB project"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|