Toon posts:

[VBA/Powerpoint] diverse problemen

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik heb een aantal vragen betreffende VBA in powerpoint. Ik ben bezig met het interactief maken van een aantal marketingmodellen in powerpoint. Dit heeft als doel dat je een presentatie kan houden voor een bedrijf met powerpoint en dat er meteen een soort van analyse uit komt rollen. Ik ben alleen op een aantal problemen gestuit en hoop dat jullie mij hiermee kunnen helpen. Ik had voordat ik aan deze opdracht ben begonnen nog weinig ervaring met VBA, maar ben na het lezen van een aantal boeken een stuk wijzer geworden. Ik mis alleen de slimmigheidjes waardoor ik soms uren achter elkaar zit te programmeren, terwijl het volgens mij een stuk sneller kan. Dat is ook een tweede reden waarom ik jullie om advies vraag.

Ik ben op de volgende problemen gestuit:

1) (Meteen het grootste probleem.) Ik wil in mijn presentatie een grafiek gebruiken. De waarden voor deze grafiek moeten komen uit de waarden die je kan invullen uit een textbox. Ik ben er alleen niet in geslaagd om bijvoorbeeld excel te koppelen aan de waardes die je in een textbox in ppt invuld. Stel je hebt 1 staaf in een grafiek en de hoogte van die staaf moet dus worden bepaald aan de hand van de waarde die je invult in textbox1. Kan iemand mij uitleggen wat de beste tactiek is.

2) Verder word ik helemaal gek van de ellenlange codes die ik soms moet invoeren, mijn vraag aan jullie of dit niet veel makkelijker kan. Ik heb bijvoorbeeld 5 checkboxes op 1 sheet staan, op de andere sheet staan dan 5 textboxes. Als je dan alleen checkbox1 aanvinkt op sheet 1 dan komt er een text te staan in slide2.textbox1. Tot zo ver alles prima. Maar...Nu wil ik dat je als je alleen checkbox1 en 5 aanvinkt dat de text die bij checkbox5 hoort in textbox2 komt te staan.

Nu heb ik dit als code (waarin ik dus alle mogelijke combinaties probeer te ondervangen):

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Private Sub CommandButton2_Click()
TextBox1.Text = ""
If Slide231.CheckBox1.Value Then infotextbox1 = "Vergrijzing"
If Slide231.CheckBox2.Value And Not Slide231.CheckBox1.Value Then infotextbox1 = "Huishoudverdunning"
If Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox1 = "Multiculturele samenleving"
If Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox1 = "Demografische druk"
If Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox1 = "Hogere levensverwachting"

TextBox1.Text = infotextbox1
TextBox6.Text = infotextbox6
TextBox7.Text = infotextbox7


TextBox2.Text = ""
If Slide231.CheckBox3.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox1.Value And Not CheckBox2.Value Then infotextbox2 = "Demografische druk"
If Slide231.CheckBox2.Value And Slide231.CheckBox1.Value Then infotextbox2 = "Huishoudverdunning"
If Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox2 = "Multiculturele samenleving"
If Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox2 = "Multiculturele samenleving"
If Slide231.CheckBox4.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value And Not Slide231.CheckBox3.Value Then infotextbox2 = "Demografische druk"
If Slide231.CheckBox5.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox4.Value Then infotextbox2 = "Hogere levensverwachting"
If Slide231.CheckBox2.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value Then infotextbox2 = "Demografische druk"
If Slide231.CheckBox2.Value And Slide231.CheckBox5.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox4.Value Then infotextbox2 = "Hogere levensverwachting"
If Slide231.CheckBox3.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value And Not Slide231.CheckBox5.Value Then infotextbox2 = "Demografische druk"
If Slide231.CheckBox3.Value And Slide231.CheckBox5.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value And Not Slide231.CheckBox4.Value Then infotextbox2 = "Hogere levensverwachting"
If Slide231.CheckBox4.Value And Slide231.CheckBox5.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value And Not Slide231.CheckBox3.Value Then infotextbox2 = "Hogere levensverwachting"
TextBox2.Text = infotextbox2

TextBox3.Text = ""
If Slide231.CheckBox2.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox3.Value And Slide231.CheckBox4.Value And Slide231.CheckBox5.Value Then infotextbox3 = "Demografische druk"
If Slide231.CheckBox1.Value And Slide231.CheckBox3.Value And Slide231.CheckBox5.Value And Not Slide231.CheckBox2.Value And Not Slide231.CheckBox4.Value Then infotextbox3 = "Hogere levensverwachting"
If Slide231.CheckBox1.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox5.Value And Not Slide231.CheckBox2.Value And Slide231.CheckBox4.Value Then infotextbox3 = "Hogere levensverwachting"
If Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox3 = "Multiculturele samenleving"
If Slide231.CheckBox4.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value And Not Slide231.CheckBox3.Value Then infotextbox3 = "Demografische druk"
If Slide231.CheckBox4.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value And Slide231.CheckBox3.Value Then infotextbox3 = "Demografische druk"
If Slide231.CheckBox5.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox4.Value Then infotextbox3 = "Hogere levensverwachting"
If Slide231.CheckBox2.Value And Slide231.CheckBox3.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox5.Value Then infotextbox3 = "Demografische druk"
If Slide231.CheckBox2.Value And Slide231.CheckBox3.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox5.Value Then infotextbox3 = "Hogere levensverwachting"
If Slide231.CheckBox2.Value And Slide231.CheckBox4.Value And Slide231.CheckBox5.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox3.Value Then infotextbox3 = "Hogere levensverwachting"
If Slide231.CheckBox3.Value And Not Slide231.CheckBox2.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox5.Value Then infotextbox3 = "Hogere levensverwachting"
TextBox3.Text = infotextbox3

TextBox4.Text = ""

If Slide231.CheckBox4.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value And Slide231.CheckBox3.Value Then infotextbox4 = "Demografische druk"
If Slide231.CheckBox5.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value And Slide231.CheckBox3.Value And Not Slide231.CheckBox4.Value Then infotextbox4 = "Hogere levensverwachting"
If Slide231.CheckBox5.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox4.Value Then infotextbox4 = "Hogere levensverwachting"
If Slide231.CheckBox5.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value And Slide231.CheckBox3.Value And Slide231.CheckBox4.Value Then infotextbox4 = "Hogere levensverwachting"
If Slide231.CheckBox5.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox2.Value And Slide231.CheckBox3.Value And Slide231.CheckBox4.Value Then infotextbox4 = "Hogere levensverwachting"
TextBox4.Text = infotextbox4

TextBox5.Text = ""
If Slide231.CheckBox5.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value And Slide231.CheckBox3.Value And Slide231.CheckBox4.Value Then infotextbox5 = "Hogere levensverwachting"
TextBox5.Text = infotextbox5


If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox1 = Slide258.TextBox1.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox2 = Slide258.TextBox2.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox3 = Slide258.TextBox3.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox4 = Slide258.TextBox4.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox5.Text

If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox2 = Slide258.TextBox1.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox3 = Slide258.TextBox2.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox4 = Slide258.TextBox3.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox4.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox5.Text

If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox3 = Slide258.TextBox1.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox4 = Slide258.TextBox2.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox3.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox4.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox7 = Slide258.TextBox5.Text

If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox4 = Slide258.TextBox1.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox2.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox3.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox7 = Slide258.TextBox4.Text

If Not Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox1.Text
If Not Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox2.Text
If Not Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox7 = Slide258.TextBox3.Text

If Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox1.Text
If Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox7 = Slide258.TextBox2.Text


If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox2 = Slide258.TextBox1.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox3 = Slide258.TextBox2.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox4 = Slide258.TextBox3.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox4.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox5.Text

If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox2 = Slide258.TextBox1.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox3 = Slide258.TextBox2.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox4 = Slide258.TextBox3.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox4.Text
If Not Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox5.Text

If Not Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox2 = Slide258.TextBox1.Text
If Not Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox3 = Slide258.TextBox2.Text
If Not Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox4 = Slide258.TextBox3.Text
If Not Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox4.Text
If Not Slide231.CheckBox5.Value And Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox5.Text

If Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox2 = Slide258.TextBox1.Text
If Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox3 = Slide258.TextBox2.Text
If Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox4 = Slide258.TextBox3.Text
If Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox5 = Slide258.TextBox4.Text
If Slide231.CheckBox5.Value And Not Slide231.CheckBox4.Value And Not Slide231.CheckBox3.Value And Not Slide231.CheckBox1.Value And Not Slide231.CheckBox2.Value Then infotextbox6 = Slide258.TextBox5.Text



TextBox1.Text = infotextbox1
TextBox2.Text = infotextbox2
TextBox3.Text = infotextbox3
TextBox4.Text = infotextbox4
TextBox5.Text = infotextbox5
TextBox6.Text = infotextbox6
TextBox7.Text = infotextbox7



End Sub


Dit is dus monnikenwerk waar ik soms helemaal van doordraai, terwijl het uiteindelijke resultaat heel simpel is. Nu is mijn vraag natuurlijk of dit makkelijker kan en hoe.

Bij voorbaat dank!!

  • OZ-Gump
  • Registratie: November 2002
  • Laatst online: 14-05-2024

OZ-Gump

terug van weggeweest

No offense, maar zelfs bij mijn resolutie van 1400 x 1050 is de layout van je topic zo vern**kt dat ik hem niet helemaal ga lezen. Verder knal je hier wel heel veel code neer.

Volgens mij heb je een aantal keuzes:
vang de checkboxes af met een aantal pull-down menu's. Indien dit niet mogelijk is: code kloppen.

Alhoewel er vast een mooiere oplossing voor te bedenken is, vindt ik dit topic niet echt uitnodigen daarover na te denken...

My personal website


Verwijderd

Je checkboxverhaaltje: gebruik een array.

Vul eerst aan de hand van je checkboxen die array, en zet dan in één keer die array over naar je sheet.

Dus, in een soort van pseudo-code:


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
If Slide231.CheckBox1.Value then array.add('je tekst');
If Slide232.CheckBox1.Value then array.add('je tekst');
    |
    |
    enz
    |
    v
infotextbox1 = array[1] 
infotextbox1 = array[2] 
    |
    |
    enz
    |
    v

[ Voor 55% gewijzigd door Verwijderd op 08-07-2004 23:04 ]


  • Lister
  • Registratie: September 2001
  • Laatst online: 15-02-2022
Ik zie door de bomen ook niet echt het bos meer, maar volgens mij helpt de volgende tip je wel een beetje:
Code als
code:
1
2
3
IF <voorwaardes1> THEN <statement1>
IF <voorwaardes1> THEN <statement2>
IF <voorwaardes1> THEN <statement3>

kan je vervangen door:
code:
1
2
3
4
5
IF <voorwaardes1> THEN
<statement1>
<statement2>
<statement3>
END IF


Want als ik het goed zie hebben een hoop van die IF-statements dezelfde voorwaardes

Verwijderd

Topicstarter
Excuses voor de overdadigheid aan code. Ik wilde uitleggen dat het naar mijn mening te veel code nodig is om iets heel simpels te bewerkstelligen. Ik begrijp goed dat het van de zotte is dat jullie die hele code gaan uitpluizen en gaan verbeteren. Mijn doel was/is om aan te geven dat er belachelijk veel code nodig is om alle combinaties weer te geven. Ik zal het nog een keer wat duidelijk uitleggen, zonder een overkill aan code.

Het is eigenlijk dus heel simpel wat ik wil bereiken. Ik heb op 1 sheet heb ik een aantal checkboxes die je kan aanvinken. Laten we zeggen 5. De 2e sheet fungeert dan als een soort van overzicht ten aanzien van de aangevinkte checkboxes en laat een stuk text zien die bij elk van de checkboxes hoort.

Dus checkbox1.value => op sheet 2 (in textbox1) komt er te staan "GOT is cool"
checkbox2.value => "Bas is cool" (in textbox2, als ook textbox1 is aangevinkt)
etc.

Nu is het "probleem" dat ik 5 textboxen op sheet 2 heb staan. Als je elke checkbox op sheet 1 koppelt aan een textbox op sheet 2 heb je geen probleem, immers elke checkbox krijgt zijn eigen textbox om een text in achter te laten. Deze ideale situatie ontstaat alleen als alle checkboxes zijn aangevinkt. Als bijvoorbeeld checkbox4 niet is aangevinkt, wil ik dat de text van checkbox5 in de textbox van checkbox4 terechtkomt, dat hij dus een plaatsje naar boven opschuift. Ze moeten dus mooi onder elkaar komen. En om elke combinatie op te vangen heb je dus zoveel code nodig. En ik hoopte dat jullie met een wat simpelere oplossing zouden komen. Ik moet deze code namelijk vaker gebruiken en hij is namelijk ietwat (understatement) omslachting. Ik zal het proberen met het invoeren van een array, zoals eerder voorgesteld, hopelijk helpt dat.

Mercurius is niet kort van stof vandaag... O-)

[ Voor 4% gewijzigd door Verwijderd op 08-07-2004 22:40 ]


Verwijderd

Lister schreef op 08 juli 2004 @ 22:24:
Ik zie door de bomen ook niet echt het bos meer, maar volgens mij helpt de volgende tip je wel een beetje:
Code als
code:
1
2
3
IF <voorwaardes1> THEN <statement1>
IF <voorwaardes1> THEN <statement2>
IF <voorwaardes1> THEN <statement3>

kan je vervangen door:
code:
1
2
3
4
5
IF <voorwaardes1> THEN
<statement1>
<statement2>
<statement3>
END IF


Want als ik het goed zie hebben een hoop van die IF-statements dezelfde voorwaardes
Nope. Het valt weg door de vernaggeling van de layout, maar wat hij wil is zeg maar maar dit:

hij heeft 5 checkboxjes met daaraan gekoppeld een tekst. Daarnaast heeft hij 5 listboxjes waar een tekst in moet.

Nu wil hij geen lege regels hebben, dus bij elk checkboxje gaat hij helemaal controleren of de eerdere checkboxjes gekozen waren en een listbox gevuld hebben.

Vandaar ook mijn voorstel met een array te werken; dat werkt stukken eenvoudiger. Je haalt eerst je teksten op, en zet die dan in volgorde in je listboxen.

@mercurius: kun je wat met mijn array voorbeeld? Want dat is echt wat je wil namelijk ;) (anders moet ik het wat verder uitwerken)

[ Voor 11% gewijzigd door Verwijderd op 08-07-2004 22:40 ]


Verwijderd

Topicstarter
Precies Generaal.

De oplossing van een array lijkt mij wel de meest logische. Je vult dus zeg (als ik het een beetje begrijp) maar een kast met een aantal lade en de textboxjes 1 t/m 5 vullen zich met de informatie uit die lade. Dus als zeg maar checkbox4 niet is aangevinkt valt stopt ie ook niks in de lade en wordt er ook niks uitgehaald. Maar das logisch.

Ik heb het net even geprobeert en VBA pakt niet de functie array.add, wel herkent hij add.array, maar als je dan een tekst daarachter neerzit d.m.v. "tekst" dan komt er een foutmelding. Ik denk dat ik wel zeker in de juiste richting zit, ik ben er bijna...

Ik heb nu dit er van gemaakt:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Private Sub CommandButton3_Click()
If Slide231.CheckBox1.Value Then Add.Array "1"
If Slide231.CheckBox2.Value Then Add.Array "2"
If Slide231.CheckBox3.Value Then Add.Array "3"
If Slide231.CheckBox4.Value Then Add.Array "4"
If Slide231.CheckBox5.Value Then Add.Array "5"

infotextbox1 = Array(1)
infotextbox2 = Array(2)
infotextbox3 = Array(3)
infotextbox4 = Array(4)
infotextbox5 = array(5)


TextBox1.Text = infotextbox1
TextBox2.Text = infotextbox2
TextBox3.Text = infotextbox3
TextBox4.Text = infotextbox4
textbox5.text = infotextbox5




End Sub


Met de vermelding dat dit dus niet werkt, omdat VBA de gebeurtenis achter add.array niet verwacht.

Verwijderd

Verwijderd schreef op 08 juli 2004 @ 22:59:
Met de vermelding dat dit dus niet werkt, omdat VBA de gebeurtenis achter add.array niet verwacht.
Je omschrijving met kast klopt, je code idd niet.. het .add voorbeeld is gestoeld op Delphi (=pascal), niet op VBA..

Ik werk zelf nooit met VBA, zal even opzoeken hoe arrays werken in VBA. Het kan dus kloppen dat als je mijn voorbeeld letterlijk neemt, dat het niet werkt.. het was meer als 'pointer' bedoeld, zeg maar :)

  • Lister
  • Registratie: September 2001
  • Laatst online: 15-02-2022
Nou is het inderdaad wat duidelijker, in VBA met een array zou het dan ongeveer zo moeten:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Private Sub CommandButton3_Click()

Dim arrInfoText(1 to 5) As String
Dim intAantal as Integer

intAantal = 0

If Slide231.CheckBox1.Value Then 
    intAantal = intAantal + 1
    arrInfoText(intAantal) = "1"
End If
If Slide231.CheckBox2.Value Then 
    intAantal = intAantal + 1
    arrInfoText(intAantal) = "2"
End If
<enzovoort>

infotextbox1 = arrInfoText(1)
infotextbox2 = arrInfoText(2)
infotextbox3 = arrInfoText(3)
infotextbox4 = arrInfoText(4)
infotextbox5 = arrInfoText(5)

TextBox1.Text = infotextbox1
TextBox2.Text = infotextbox2
TextBox3.Text = infotextbox3
TextBox4.Text = infotextbox4
textbox5.text = infotextbox5

End Sub


Het zou nog veel mooier kunnen met een dynamische array of een collectie maar dat bewaren we wel voor een andere keer :P
En waarom moet het eigenlijk eerst in de infotextbox<X> variabelen, je zou ze ook direct in de textboxen kunnen zetten.

Verwijderd

Kent VBA geen inc() functie? Dan zou je zoiets:

code:
1
i=i+1


nog kunnen afkorten tot:

code:
1
inc(i)


En andere mogelijkheid (waarvan ik niet weet of VBA het kan)

code:
1
i++

Verwijderd

Topicstarter
Lister en de Generaal,

Heel erg bedankt! Het werkt perfect. Eigenlijk moet ik een heel klein traantje laten, omdat ik er wel heel erg veel werk in heb gestopt om het op de oude manier te laten functioneren. Maar goed, ik zie het maar als een investering 8)7 ...(Ik had al zo een idee toen ik het aan het programmeren was...of het was eigenlijk meer hoop: Dit kan vast beter en vooral sneller!!)

Het werkt dus perfect met de door Lister verstrekte code. Volgens mij zoals De Generaal het ook wilde uitleggen.

Mijn dank is groot.

[ Voor 6% gewijzigd door Verwijderd op 09-07-2004 00:04 ]

Pagina: 1