?
Solved

VB Radio BUtton QUestions

Posted on 2003-02-22
52
Medium Priority
?
231 Views
Last Modified: 2010-05-01
Hi experts
i got a form with a number of questions
for each question, there are 5 radio buttons
When they click on the radio button, i save the .caption into a txt file :

For Each ctl In Me.Controls
  If (TypeOf ctl Is OptionButton) Then
      If ctl.Value = True Then
          Print #ff, ctl.Caption
         
          ctl.Value = False
      End If
  End If
Next ctl


now i need to make sure that each questions as 1 radio button clicked.

how can i do that ??

thx
0
Comment
Question by:Italbro5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 28
  • 23
52 Comments
 
LVL 5

Expert Comment

by:Rhaedes
ID: 7999718
Hello again, Italbro,
Do the following:
Make all your radio buttons part of a control array. (You can set this up by copying a control and pasting it repeatedly.)
For each question, put a frame on your form. Put five of these radio buttons in each frame. This is goups the radio buttons so that only one can be active in each frame.
Then add:

Private Sub Option1_Click(Index As Integer)
Print #ff, Option1(index).Caption
End Sub

Kindest regards,
Rhaedes
0
 

Author Comment

by:Italbro5
ID: 8000082
Sup Rhaedes

look thats what i have

for each frame, i had 5 control button :
Do While Y < 5

Form1.Controls.Add "VB.OptionButton", "Option" & (d) & (Y), oFrame
Dim oOption As VB.OptionButton
Set oOption = Form1.Controls("Option" & (d) & (Y))
With oOption

.Caption = "" & (Y)
.FontSize = 12
.Visible = True
.Left = var_num3
.Top = var_num4 + 130
.Width = 750
.Height = 300
.Alignment = oPicture

End With

Y = Y + 1
Z = Z + 1
var_num3 = var_num3 + 1100

Loop


then i click on a cmdButton and i need to save all the answer in a .txt file. Thats not a problem. what i need is

1- to make sure that in each frame, there is 1 radio button clicked. If one or more is missing, MSGBOX saying , question # .. is not answer, and once there all answer, i can save all the answer into a .txt

all i got to do is make sure there answer or else cant save answers

thx
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8000265
Here is a fairly neat code segment that should do what you want.

Dim BoolCheck As Boolean

Private Sub Check1_Click()

If Check1.Value = vbChecked Then
 BoolCheck = True
End If

If Check1.Value = vbUnchecked Then
 BoolCheck = False
End If

End Sub

Private Sub Command1_Click()
 Dim inI As Integer
 Dim BoolMessage(1 To Whatever) As Boolean
 Dim inJ As Integer
 Dim MessageString As String
 Dim inCurrent as integer

 For inJ = 1 To Whatever

BoolMessage(inJ) = False

For inI = 1 To 5
 inCurrent = (inJ-1)*5 + inI - 1
 If Option1(inCurrent).Value = True Then
 BoolMessage(inJ) = True
End If

Next inI

If BoolMessage(inJ) = False Then
 MessageString = "Question # " + inJ + " is not filled  in.  Please do so now."
 Call msgBox (MessageString,vbInformation)

Next inJ

End Sub

I think this will do it.

Jacamar
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Italbro5
ID: 8000357
Jacamar
sorry
but it dosent work
i create evrything dinamicly so it wont work
i dont really understand your code, i tried it but it dosent work.

I need to go over each "Option" & (d) & (Y)
to see if at least one " Y " is checked

thx
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8001137
Ok, here is an example I tried that worked.  It has 2 frames with 5 options in each frame.  Sorry about the about that didn't work.  My option array is called
'Option1()' and it ranges from 0 to 9.  

Dim BoolCheck As Boolean

Private Sub Command1_Click()
Dim inI As Integer
Dim BoolMessage(1 To 2) As Boolean
Dim inJ As Integer
Dim MessageString As String
Dim inCurrent As Integer

For inJ = 1 To 2

BoolMessage(inJ) = False

For inI = 1 To 5
inCurrent = (inJ - 1) * 5 + inI - 1
If Option1(inCurrent).Value = True Then
BoolMessage(inJ) = True
End If

Next inI

If BoolMessage(inJ) = False Then
MessageString = "Question # " & inJ & " is not filled  in.  Please do so now."
Call MsgBox(MessageString, vbInformation)
End If
Next inJ

End Sub

If you have problems with this, let me know what specifically is the problem.

Jacamar
0
 

Author Comment

by:Italbro5
ID: 8003446
Hi
the thing is that i dont know how many frames i got
so If Option1(inCurrent).Value = True Then will work for only the first two but then it wont work for the other ones.

thats what i have :
"Option" & (d) & (Y)

Option & (1) & (1)
Option & (1) & (2)
Option & (1) & (3)....
Option & (2) & (1)
Option & (2) & (2)....

thx
Italbro
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8005225
ok,

dim inNumFrames as integer
dim inNumOptions as integer
dim BoolMessage() as Boolean


inNumFrames = whatever
Redim BoolMessage(1 to inNumFrames) as Boolean
For inI = 1 to inNumFrames
BoolMessage(inI) = False
Next inI

For inI = 1 to inNumFrames
 For inJ = 1 to inNumOptions
  if Option & (inI) & (inJ).Value = true then
   BoolMessage(inI) = True
  end if
 Next inJ
Next inI

For inI = 1 to inNumFrames

 if BoolMessage (inI) = True then
  Call msgBox ("Frame "& inI & " is not filled in", vbinformation)
 end if

Next inI

is this going to work for you?
0
 

Author Comment

by:Italbro5
ID: 8005531
Hey
sorry if i bust, but the problem is :

 if Option & (inI) & (inJ).Value = true then
 this dosent work

cause i create evrything dinamicly so i cant try n find
Option & (inI) & (inJ) cause it dosent exist

you understand ??


thats what i use to save the .caption of each :
Dim ctl As Control
For Each ctl In Me.Controls
   If (TypeOf ctl Is OptionButton) Then
       If ctl.Value = True Then
           Print #ff, ctl.Caption
           
           ctl.Value = False
       End If
   End If
Next ctl

try and get all the Contols that are Option buttons
its complicated, i just dont see how to do it
thats why i need your help

thx alot
Italbro
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8005616
ok, lets start over.  You have a number of frames....each of which contain some options buttons.  And you need to make sure that each frame has one option selected before the user is allowed to proceed.  How many frames are you going to have?  And if you are not sure, how is that going to be determined?  Or could it be different every time?  What kind of options are these going to be?  I think there will be a simpler way to go about doing what you are trying to do.  
0
 

Author Comment

by:Italbro5
ID: 8005659
Here it is
i read a text file.
in the .txt file, there are some question
1.1 ..
1.2....
....
for each question, i create a frame + 5 radio-buttons.
THe amount of frames, i dont know, depends how many questions in the .txt file

here's what i have :

Form1.Controls.Add "VB.Frame", "Frame" & (i), Frame1
    Dim oFrame  As VB.Frame
    Set oFrame = Form1.Controls("Frame" & (i))
    With oFrame
    .BorderStyle = 0
    .Height = 500
    .Width = 6000
    .Left = 100
    .Visible = True
    .Top = var_num2
    End With


Do While Y < 5
Form1.Controls.Add "VB.OptionButton", "Option" & (d) & (Y), oFrame
Dim oOption As VB.OptionButton
Set oOption = Form1.Controls("Option" & (d) & (Y))
With oOption

.Caption = "" & (Y)
.FontSize = 12
.Visible = True
.Left = var_num3
.Top = var_num4 + 130
.Width = 750
.Height = 300
.Alignment = oPicture

End With


thats the code i use to create the frames and radio buttons.

SO i need to make sure that each frame ( every questions ) has one option selected before the user is allowed to proceed ( save all the answers in an other .txt file )
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8005792
One thing that would make this a much simpler problem would be if in the textfile you could add a line at the start of the file when it is made.  If this were the first line of the file, you could input that value and use it to tell your program how many frames there are.  Is this possible?

Or when the questions are being inputed in to the program, you could have a counter to count how many questions there are.  You can add a

Counter = Counter + 1

Each time a line is inputed.  Or each time a new frame is created.  

Will either of these be useful in your case?  It will make the code I have above useful since you will beable to set:

inNumFrames = Counter

Once the form is loaded.

Jacamar
0
 

Author Comment

by:Italbro5
ID: 8005833
Counter = Counter + 1
 its a good idea
thats not a problem to do

but the thing is this :
to get the value of the radio button, i do this

Dim ctl As Control
For Each ctl In Me.Controls
  If (TypeOf ctl Is OptionButton) Then
      If ctl.Value = True Then
          Print #ff, ctl.Caption
         
          ctl.Value = False
      End If
  End If
Next ctl


thats the thing, i cant go for Option(1)(2)...
i need to check

for each frame, in the 5 radio button, one as to be click
0
 

Author Comment

by:Italbro5
ID: 8005842
you got no choice to use
something like that, cause evrything is create dinamicly

Dim ctl As Control
For Each ctl In Me.Controls
 If (TypeOf ctl Is OptionButton) Then
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8005903
if you add the counter = counter + 1, then you should beable to write loops that will be done a certian number of times depending on the counter number.  

Since the options buttons will be created as array, won't you beable to use the value of the counter to check them all?
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8005913
what I mean is.  Although things will always be created dinamicly, you can still keep track of this through the counter.  This can trasform your program to something that is 'static' as far as the variables are concerned
0
 

Author Comment

by:Italbro5
ID: 8007988
JAcamar
i create evrything on form2
i had a button there
what will be the code that i need to use for what i need.
thx
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8009202
Ok, once you have the frames and buttons created, you should have value for your counter.  This will either have counted the number of buttons you made, or the number of frames you made.  
If it is the number of frames, then you can leave it, if it is the number of  buttons, then divide that number by 5 so that you will have the number of frames.  

ok, now.  

dim inI as integer
dim inJ as integer
dim BoolOption() as Boolean
dim BoolMessage as Boolean
dim MessageString as String

Redim BoolOption(1 to Counter) as Boolean
For inI = 1 to Counter
 BoolOption(inI) = False
   '  Each time set this option to false.
 For inJ = 1 to 5
  If Option(inI)(inJ).value = true then
   BoolOption(inI) = True
  End if
 Next inJ
Next inI

'  The above code will go through all frames (inI's), and check all buttons in each frame(inJ's) to make sure one is chosen.  If none are chosen in a frame, the 'BoolOption will remain False for that inI.  Once this is done, you can do something like

MessageSting = "Please Fill in the Following Questions"
BoolMessage = False

For inI = 1 to Counter
 if BoolOption(inI) = False then
  BoolMessege = True
  MessageString =MessageString & ", " & inI
 end if
Next inI

'  IF any of the questions are not filled in, then the BoolMessage will be true and it will execute the following.

if BoolMessege = True then
 Call msgBox(MessageString, vbinformation)
end if

'  And accordingly

if BoolMessege = False then
Call cmdProccessInfo_Click()
end if

Let me know if this works for you.

Jacamar.
0
 

Author Comment

by:Italbro5
ID: 8010230
here are my two option JACAMAR

1- either i create a dynamic button = i'm not able to make it work when clicked .. if u can help !!!!!

2- if i create the button my self and add your code on the cmd_click() it wont work because : Option(inI)(inJ) dosent exist. Option()() was create dynamicly so i wont be able to work with it.

your code is exaclty what i need.

thx
Italbro
0
 

Author Comment

by:Italbro5
ID: 8010594
hey JACAMAR
i made the button work but it dosent work

this code here is not good :
If Option(inI)(inJ).value = true then

it dosent work

i need to paste the code into a button and it gives me an error at the line before.

i think were getting closer but it dosent work

i appreciate your help,
almost done
thx
0
 

Author Comment

by:Italbro5
ID: 8010717
when i said previously : i made the button work but it dosent work

it means, i was able to make the button_click() work but the code inside dosent.
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8010909
Are you able to create the buttons on the frames on your form?

If so, what are the names of the buttons?
0
 

Author Comment

by:Italbro5
ID: 8011014
lol
it think we dont understand each other.

i got a frame.
in the frame i got labels
under each label i got 5 radio-button in a frame
at the end of the frame, i got a cmd_button
when i click on the cmd_button, it checks if on radio button as been click in each frame.

the thing is, i create evrything dynamicly so it dosent recognize the Option(inI)(inJ) so i need to do it a different way

i think i cant be clearer then that
sorry if i give you problem to understand

thx
italbro
0
 

Author Comment

by:Italbro5
ID: 8011017
i got a BIG FRAME
in the frame i got labels
under each label i got 5 radio-button in a frame to put the radio-buttons together
at the end of the BIG FRAME, i got a cmd_button
when i click on the cmd_button, it checks if on radio button as been click in each frame.

0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8011063
ok, and what are the names of these option buttons?
0
 

Author Comment

by:Italbro5
ID: 8011347
i create them dynamicly
Option(inI)(inJ)
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8011524
Ok, so once they are created, and you have the value for your counter, why can you not use the counter to run loops to check all of Option(inI)(inJ)?

For inI = 1 to Counter
For inJ = 1 to Counter*5

ect.....like I did before?
0
 

Author Comment

by:Italbro5
ID: 8011719
cause when u create Option(inI)(inJ) dynamicli
u cant do Option(1)(1).value ... it wont work
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8011979
Ok, I gave it a try.  I put 15 options on the screen in an array, ctl() and it is redimensioned to ctl(1 to 3, 1 to 5)

These options are not in frames, but it shouldn't make a difference if they are.  It goes through and checks in groups of 5's, and messegeboxes pop up to notify which groups of 5 do not have an option selected.  Since they are all on the same form in this example, at least 2 pop up.  Try this code in a new application and only add a new command button.  It works with the dinamically determined options buttons  that are:

ctl(inI,inJ)




Dim ctl() As Control

Private Sub Form_Load()
Form1.Width = 10000
Form1.Height = 10000
Dim frm As Form1

Dim lX As Long
Dim lY As Long
Dim lInc As Long
Dim i As Integer

   lInc = 400
   
   'create 5 Option Buttons
   
   Counter = 3
ReDim ctl(1 To Counter, 1 To 5)
ReDim ctl1(1 To Counter)
   
  With Form1
   For inI = 1 To Counter

   For inJ = 1 To 5
           
           Set ctl(inI, inJ) = .Controls.Add("VB.OptionButton", "Option" & CStr(inI) & CStr(inJ))
           
           ctl(inI, inJ).Top = lY
           ctl(inI, inJ).Left = 100
           ctl(inI, inJ).Width = 4000
           ctl(inI, inJ).Caption = "This is Option #" & CStr(inJ)
           ctl(inI, inJ).Visible = True
           lY = lY + lInc
       
Next inJ
   Next inI
   End With
   Form1.Show vbModal
   
   Set Form1 = Nothing


End Sub



Private Sub Command1_Click()
Dim inI As Integer
Dim inJ As Integer
Dim BoolOption(1 To 3) As Boolean

For inI = 1 To 3
For inJ = 1 To 5
OptionName = "Option" & CStr(inI) & CStr(inJ)
If ctl(inI, inJ).Value = True Then
BoolOption(inI) = True
End If
Next inJ
Next inI

For inI = 1 To 3
If BoolOption(inI) = False Then
Call MsgBox(inI, vbInformation)
End If
Next inI


End Sub

Let me know what happens this time.  LOL.  Hopefully we are on the same page now.

Jacamar
0
 

Author Comment

by:Italbro5
ID: 8013779
LOL

it dosent really do something usefull

try n create the frames and then put the 5 radio buttons.
Now its create 15 radio button, 3 time 1 to 5, but i can check only one on all 15. And then msgbox only 2 numbers, dont really get.

Try and make 2 frames, with 5 radio, then a button and then it will work, thx
italbro
0
 

Author Comment

by:Italbro5
ID: 8013853
i'm gonna need to use something like that
For Each ctl In Me.Controls
  If (TypeOf ctl Is OptionButton) Then
 i think
0
 

Author Comment

by:Italbro5
ID: 8017949
JACAMAR
did you find anything interesting for me

0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8018110
Are you able to get your program to create your frames and buttons?
0
 

Author Comment

by:Italbro5
ID: 8018139
JACAMAR


ya
thats not a problem

i read a text file
i had a Frame with 5 Radio Button in the frame

thats not a problem

its to make sure that there all check that i cant do
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8018322
ok.  The code I gave you yesterday will check the options buttons in groups of 5 to make sure that at least one is checked right?  

So when you create your options, why don't you just create them with the same name in a one dimensional array, and I have shown that you can check them that way?

What is your code to create the frames and options now?
0
 

Author Comment

by:Italbro5
ID: 8018586
this is my code :

Do While Not EOF(1)
var_num3 = 100
Line Input #1, MyString
Dim MyString2
Dim MyString3

MyString2 = Mid(MyString, 1, 1)
MyString3 = Mid(MyString, 3, 1)

If MyString <> "" Then
Form1.Controls.Add "VB.Label", "Label" & (i), Frame1
Dim oLabel As VB.Label
Set oLabel = Form1.Controls("Label" & CStr(i))
With oLabel
.Top = var_num1
.Visible = True
.Caption = MyString
.AutoSize = True
.BorderStyle = 1
.Left = 100
End With
i = i + 1
End If

If MyString3 > 0 And MyString3 < 9 Then
Y = 0

Form1.Controls.Add "VB.Frame", "Frame" & (i), Frame1
Dim oFrame  As VB.Frame
Set oFrame = Form1.Controls("Frame" & (i))
With oFrame
.BorderStyle = 0
.Height = 500
.Width = 6000
.Left = 100
.Visible = True
.Top = var_num2

End With
Do While Y < 5

Form1.Controls.Add "VB.OptionButton", "Option" & (d) & (Y), oFrame
Dim oOption As VB.OptionButton
Set oOption = Form1.Controls("Option" & (d) & (Y))
With oOption

.Caption = "" & (Y)
.FontSize = 12
.Visible = True
.Left = var_num3
.Top = var_num4 + 130
bouton = var_num4 + 130
.Width = 750
.Height = 300
.Alignment = oPicture

End With

Y = Y + 1
Z = Z + 1
var_num3 = var_num3 + 1100

Loop
d = d + 1

End If
var_num1 = var_num1 + 800
var_num2 = var_num2 + 800

Loop

i'll try n work on it

but if u have the code for something like this, it would be great

thx
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8019778
Ok, i've done a bit of playing around with this.  Copy this code, and paste it in to a  new application.  Put on two new control buttons, Command1 and Command2.

Then give it a try.  Make sure you change the name of the text file though.


Dim ctl() As Control
Dim d As Integer

Private Sub Command1_Click()
FileName = App.Path + "\Text.txt"
Open FileName For Input As #1

d = 1

Do While Not EOF(1)
var_num3 = 100
Line Input #1, MyString
Dim MyString2
Dim MyString3

MyString2 = Mid(MyString, 1, 1)
MyString3 = Mid(MyString, 3, 1)

If MyString <> "" Then
Form1.Controls.Add "VB.Label", "Label" & (i)
Dim oLabel As VB.Label
Set oLabel = Form1.Controls("Label" & CStr(i))
With oLabel
.Top = var_num1
.Visible = True
.Caption = MyString
.AutoSize = True
.BorderStyle = 1
.Left = 100
End With
i = i + 1
End If

If MyString3 > 0 And MyString3 < 9 Then
y = 1

Form1.Controls.Add "VB.Frame", "Frame" & (i)
Dim oFrame  As VB.Frame
Set oFrame = Form1.Controls("Frame" & (i))
With oFrame
.BorderStyle = 0
.Height = 500
.Width = 6000
.Left = 100
.Visible = True
.Top = var_num2

End With
Do While y < 6

Form1.Controls.Add "VB.OptionButton", "Option" & (d) & (y), oFrame
ReDim ctl(1 To d, 1 To 5) As Control
Set ctl(d, y) = Form1.Controls("Option" & (d) & (y))
With ctl(d, y)

.Caption = "" & (y)
.FontSize = 12
.Visible = True
.Left = var_num3
.Top = var_num4 + 130
bouton = var_num4 + 130
.Width = 750
.Height = 300
.Alignment = oPicture

End With

y = y + 1
Z = Z + 1
var_num3 = var_num3 + 1100

Loop
d = d + 1

End If
var_num1 = var_num1 + 800
var_num2 = var_num2 + 800

Loop

End Sub


Private Sub Command2_Click()
Dim inI As Integer
Dim inJ As Integer
Dim BoolOption() As Boolean
ReDim BoolOption(1 To d)
For inI = 1 To d - 1

For inJ = 1 To 5
OptionName = "Option" & CStr(inI) & CStr(inJ)

Set ctl(inI, inJ) = Form1.Controls("Option" & (inI) & (inJ))
If ctl(inI, inJ) = True Then
       
        BoolOption(inI) = True
       
End If
Next inJ
Next inI

For inI = 1 To d - 1
If BoolOption(inI) = False Then
Call MsgBox("Please Fill in Question # " & inI, vbInformation)
End If
Next inI


End Sub

Jacamar
0
 

Author Comment

by:Italbro5
ID: 8022362
your code looks ok
some spacing to do

one thing do.
if there all answered i need to save all the caption or value into a file.

Print #ff, ctl.Caption

thats what i use to do, but now i need to make sure there all answered
how can i do that

once and only once there all answered i save evrything


0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8022575
Ok, here is the fixed code that will do that.  Take the same steps as before.  Just 2 command buttons.  I spaced it out a bit for you this time .....    :)

Dim ctl() As Control
Dim d As Integer

Private Sub Command1_Click()

Filename = App.Path + "\Text.txt"

Open Filename For Input As #1

d = 1

Do While Not EOF(1)

    var_num3 = 100

    Line Input #1, MyString

    Dim MyString2
    Dim MyString3

    MyString2 = Mid(MyString, 1, 1)
    MyString3 = Mid(MyString, 3, 1)

If MyString <> "" Then

    Form1.Controls.Add "VB.Label", "Label" & (i)
    Dim oLabel As VB.Label
    Set oLabel = Form1.Controls("Label" & CStr(i))
   
    With oLabel
        .Top = var_num1
        .Visible = True
        .Caption = MyString
        .AutoSize = True
        .BorderStyle = 1
        .Left = 100
    End With
    i = i + 1
End If

If MyString3 > 0 And MyString3 < 9 Then

y = 1

Form1.Controls.Add "VB.Frame", "Frame" & (i)

Dim oFrame  As VB.Frame

Set oFrame = Form1.Controls("Frame" & (i))

With oFrame
    .BorderStyle = 0
    .Height = 500
    .Width = 6000
    .Left = 100
    .Visible = True
    .Top = var_num2
End With

    Do While y < 6

        Form1.Controls.Add "VB.OptionButton", "Option" & (d) & (y), oFrame
        ReDim ctl(1 To d, 1 To 5) As Control
        Set ctl(d, y) = Form1.Controls("Option" & (d) & (y))
       
        With ctl(d, y)

        .Caption = "" & (y)
        .FontSize = 12
        .Visible = True
        .Left = var_num3
        .Top = var_num4 + 130
        bouton = var_num4 + 130
        .Width = 750
        .Height = 300
        .Alignment = oPicture

        End With

            y = y + 1
            Z = Z + 1
            var_num3 = var_num3 + 1100

        Loop
        d = d + 1

    End If
    var_num1 = var_num1 + 800
    var_num2 = var_num2 + 800

Loop

Close #1

Command1.Enabled = False

End Sub


Private Sub Command2_Click()

Dim inI As Integer
Dim inJ As Integer
Dim BoolOption() As Boolean
Dim AnswerVal() As Integer
Dim BoolProceed As Boolean

ReDim BoolOption(1 To d)
ReDim AnswerVal(1 To d)

For inI = 1 To d - 1
    For inJ = 1 To 5
       
        OptionName = "Option" & CStr(inI) & CStr(inJ)

        Set ctl(inI, inJ) = Form1.Controls("Option" & (inI) & (inJ))
       
        If ctl(inI, inJ) = True Then
            AnswerVal(inI) = inJ
            BoolOption(inI) = True
        End If
       
    Next inJ
Next inI

BoolProceed = True

For inI = 1 To d - 1
    If BoolOption(inI) = False Then
        Call MsgBox("Please Fill in Question # " & inI, vbInformation)
        BoolProceed = False
    End If
Next inI


If BoolProceed = True Then
   
    Dim Filename As String

    Filename = App.Path + "\Answers.txt"

    Open Filename For Output As #2

    For inI = 1 To d - 1
        Print #2, inI; Tab(5); " = ";
        Print #2, Tab(9); AnswerVal(inI)
    Next inI

    Close #2
   
    Call MsgBox("Values have been saved to " & Filename, vbInformation)

End If

End Sub

Let me know how this works.
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8027082
Italbro,

How did that work out for you?  Is your program moving along now?

Jacamar.
0
 

Author Comment

by:Italbro5
ID: 8027259
hey Jacamar
i'm working on it, let me try it
i'll post a reply today
thx
0
 

Author Comment

by:Italbro5
ID: 8029478
it looks butyfull
but
few little things i tried n work on them, i screwed evrything up.

1- its not 1 to 5, but 0 - 4
2- it dosent have to say all the # he didnt answer. It says you didnt answert to #3. then he continues, he forgor and other one, didnt answer # 20 .... you know.
3- its not questions 6 but maybe 2.2 or 3.1

after this, its perfect, i think.
i really appreciate your help
when done, a straigth A, and if u want more, i got a couple of more questions that are not close yet,... lol
ciao
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8029513
Yeah, those changes I made, I meant to change back, the 1 to 5, and I just put those messege boxes in so you could see that it was working.  

I'm glad you like it, and that it will help.   :)

Jacamar
0
 

Author Comment

by:Italbro5
ID: 8029635
Jacamar
these things dont work
can u fix them
the
1-
2-
3-

if u dont mind
i'mt rying now, but i'm screwing things up
thx
0
 

Author Comment

by:Italbro5
ID: 8029706
one last thing with the other 3
can you pus some comments, i'm a bit lost
just little thing, that does that ....
like this i can understand better
thx
Italbro
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8029951
1- and 2-  are no problem, but I don't know what you are asking in 3-.  Explain that one a bit more.
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8030044
Ok, try this one now


Dim ctl() As Control
Dim d As Integer


Private Sub Command1_Click()

Filename = App.Path + "\Text.txt"

Open Filename For Input As #1

d = 1

Do While Not EOF(1)

   var_num3 = 100

   Line Input #1, MyString

   Dim MyString2
   Dim MyString3

   MyString2 = Mid(MyString, 1, 1)
   MyString3 = Mid(MyString, 3, 1)

If MyString <> "" Then

   Form1.Controls.Add "VB.Label", "Label" & (i)
   Dim oLabel As VB.Label
   Set oLabel = Form1.Controls("Label" & CStr(i))
   
   With oLabel
       .Top = var_num1
       .Visible = True
       .Caption = MyString
       .AutoSize = True
       .BorderStyle = 1
       .Left = 100
   End With
   i = i + 1
End If

If MyString3 > 0 And MyString3 < 9 Then

y = 0

Form1.Controls.Add "VB.Frame", "Frame" & (i)

Dim oFrame  As VB.Frame

Set oFrame = Form1.Controls("Frame" & (i))

With oFrame
   .BorderStyle = 0
   .Height = 500
   .Width = 6000
   .Left = 100
   .Visible = True
   .Top = var_num2
End With

   Do While y < 5

       Form1.Controls.Add "VB.OptionButton", "Option" & (d) & (y), oFrame
       ReDim ctl(1 To d, 0 To 4) As Control
       Set ctl(d, y) = Form1.Controls("Option" & (d) & (y))
       
       With ctl(d, y)

       .Caption = "" & (y)
       .FontSize = 12
       .Visible = True
       .Left = var_num3
       .Top = var_num4 + 130
       bouton = var_num4 + 130
       .Width = 750
       .Height = 300
       .Alignment = oPicture

       End With

           y = y + 1
           Z = Z + 1
           var_num3 = var_num3 + 1100

       Loop
       d = d + 1

   End If
   var_num1 = var_num1 + 800
   var_num2 = var_num2 + 800

Loop

Close #1

Command1.Enabled = False

End Sub


Private Sub Command2_Click()

Dim inI As Integer
Dim inJ As Integer
Dim BoolOption() As Boolean
Dim AnswerVal() As Integer
Dim BoolProceed As Boolean

ReDim BoolOption(1 To d)
ReDim AnswerVal(1 To d)

For inI = 1 To d - 1        ' Checking all questions
   For inJ = 0 To 4         ' Checking all answers
       
       OptionName = "Option" & CStr(inI) & CStr(inJ)   'OptionName

       Set ctl(inI, inJ) = Form1.Controls("Option" & (inI) & (inJ))
       
       If ctl(inI, inJ) = True Then
           ' if an answer is selected, then it does this
           AnswerVal(inI) = inJ
           BoolOption(inI) = True
       End If
       
   Next inJ
Next inI

BoolProceed = True

For inI = 1 To d - 1
   If BoolOption(inI) = False Then
       BoolProceed = False
       '    if any question does not have one option chosen then
       '    it will record it as BoolProceed
   End If
Next inI


If BoolProceed = True Then      'if all questions are filled
   
   Dim Filename As String

   Filename = App.Path + "\Answers.txt"

   Open Filename For Output As #2

   For inI = 1 To d - 1
       Print #2, inI & "." & AnswerVal(inI)     'Output question.answer
   Next inI                                     '    Ex. 1.2 or 3.4

   Close #2
   
   Call MsgBox("Values have been saved to " & Filename, vbInformation)
    '   tells you where the file is
End If

End Sub
0
 

Author Comment

by:Italbro5
ID: 8030419
#3 is on your exemple it use to say
question #34 is not answered
but the thing is in my file its not the same
the questions are
2.1 Are People ...
2.2 Is Mickeal ....
4.5 HOw come ....

and so one.
but this i dont know if u can help^
what i'm gonna do is take the first 3 numbers of each and put it where its missing

but not in your last exemple there is no error ( msgbox if there missing an answer ) when there missing a #
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8030962
so what do you want it to do now?  I don't really understand.  Does it work now?  

We'll figure this one out yet!

Jacamar.
0
 

Author Comment

by:Italbro5
ID: 8032908
there need to be an msgbox if there missing an answer  if there missing one answer, the thing is before, it use to say all the answers missing, if there missing more then one, i just one an MsgBox saying the first question missing is.. doesent have to show ALL the quesitons missing but only the first one.
0
 
LVL 2

Accepted Solution

by:
Jacamar earned 200 total points
ID: 8033908
Dim ctl() As Control
Dim d As Integer


Private Sub Command1_Click()

Filename = App.Path + "\Text.txt"

Open Filename For Input As #1

d = 1

Do While Not EOF(1)

  var_num3 = 100

  Line Input #1, MyString

  Dim MyString2
  Dim MyString3

  MyString2 = Mid(MyString, 1, 1)
  MyString3 = Mid(MyString, 3, 1)

If MyString <> "" Then

  Form1.Controls.Add "VB.Label", "Label" & (i)
  Dim oLabel As VB.Label
  Set oLabel = Form1.Controls("Label" & CStr(i))
 
  With oLabel
      .Top = var_num1
      .Visible = True
      .Caption = MyString
      .AutoSize = True
      .BorderStyle = 1
      .Left = 100
  End With
  i = i + 1
End If

If MyString3 > 0 And MyString3 < 9 Then

y = 0

Form1.Controls.Add "VB.Frame", "Frame" & (i)

Dim oFrame  As VB.Frame

Set oFrame = Form1.Controls("Frame" & (i))

With oFrame
  .BorderStyle = 0
  .Height = 500
  .Width = 6000
  .Left = 100
  .Visible = True
  .Top = var_num2
End With

  Do While y < 5

      Form1.Controls.Add "VB.OptionButton", "Option" & (d) & (y), oFrame
      ReDim ctl(1 To d, 0 To 4) As Control
      Set ctl(d, y) = Form1.Controls("Option" & (d) & (y))
     
      With ctl(d, y)

      .Caption = "" & (y)
      .FontSize = 12
      .Visible = True
      .Left = var_num3
      .Top = var_num4 + 130
      bouton = var_num4 + 130
      .Width = 750
      .Height = 300
      .Alignment = oPicture

      End With

          y = y + 1
          Z = Z + 1
          var_num3 = var_num3 + 1100

      Loop
      d = d + 1

  End If
  var_num1 = var_num1 + 800
  var_num2 = var_num2 + 800

Loop

Close #1

Command1.Enabled = False

End Sub


Private Sub Command2_Click()

Dim inI As Integer
Dim inJ As Integer
Dim BoolOption() As Boolean
Dim AnswerVal() As Integer
Dim BoolProceed As Boolean

ReDim BoolOption(1 To d)
ReDim AnswerVal(1 To d)

For inI = 1 To d - 1        ' Checking all questions
  For inJ = 0 To 4         ' Checking all answers
     
      OptionName = "Option" & CStr(inI) & CStr(inJ)   'OptionName

      Set ctl(inI, inJ) = Form1.Controls("Option" & (inI) & (inJ))
     
      If ctl(inI, inJ) = True Then
          ' if an answer is selected, then it does this
          AnswerVal(inI) = inJ
          BoolOption(inI) = True
      End If
     
  Next inJ
Next inI

BoolProceed = True

For inI = 1 To d - 1
  If BoolOption(inI) = False Then
      BoolProceed = False
      '    if any question does not have one option chosen then
      '    it will record it as BoolProceed
  End If
Next inI


If BoolProceed = False then
 Call MsgBox("Please fill in all questions", vbInformation)
End If

If BoolProceed = True Then      'if all questions are filled
 
  Dim Filename As String

  Filename = App.Path + "\Answers.txt"

  Open Filename For Output As #2

  For inI = 1 To d - 1
      Print #2, inI & "." & AnswerVal(inI)     'Output question.answer
  Next inI                                     '    Ex. 1.2 or 3.4

  Close #2
 
  Call MsgBox("Values have been saved to " & Filename, vbInformation)
   '   tells you where the file is
End If

End Sub
0
 

Author Comment

by:Italbro5
ID: 8034055
thx alot Jacamar
really appreciate
thx again
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8035572
t'was my pleasure.....:)

Jacamar
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question