1 / 14

ListBox1.Clear ' リストボックスのクリア

ListBox1.Clear ' リストボックスのクリア. Dim a As Integer 'a 乱数時間 Dim t As Long, r As Long 't 出題時の秒数、 r  解答にかかった秒数 Dim j As String ' 判定の文言 a = Int(Rnd(1) * 8 + 3) ' 時間を乱数で決定、 3 ~ 10(8+3 秒未満 ) 秒の間 t = Timer ' 現在の時間を記録 MsgBox a & " 秒後に OK を押せ! "

dani
Télécharger la présentation

ListBox1.Clear ' リストボックスのクリア

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ListBox1.Clear 'リストボックスのクリア Dim a As Integer 'a 乱数時間 Dim t As Long, r As Long 't 出題時の秒数、r 解答にかかった秒数 Dim j As String '判定の文言 a = Int(Rnd(1) * 8 + 3) '時間を乱数で決定、3~10(8+3秒未満)秒の間 t = Timer '現在の時間を記録 MsgBox a & "秒後にOKを押せ!" r = Timer - t '解答にかかった時間を算出 j = "誤差" & r - a & "秒 " '解答にかかった時間から出題時間を引いて誤差を算出 If r = a Then j = j & "ジャスト!" If r > a Then j = j & "時間かけ過ぎ!" If r < a Then j = j & "早いよ!" MsgBox j '判定の内容を表示 ListBox1.AddItem (j) 'リストボックスに記録 結果によって表示などを変えるときは、変数に結果に対応した文言を格納し、 最後にMsgBoxやAddItemを使って表示、登録させるとシンプルなプログラムになる

  2. ListBox1.Clear ListBox2.Clear ListBox1.AddItem ("青方偏移") ListBox1.AddItem ("ワープ") ListBox1.AddItem ("バリヤー") ListBox1.Clear ListBox2.Clear ListBox1.AddItem ("A.オリゼー") ListBox1.AddItem ("C.トリコイデス") ListBox1.AddItem ("A.アセチ") ListBox1.Clear ListBox2.Clear ListBox1.AddItem ("錬金術") ListBox1.AddItem ("ポリウォーター") ListBox1.AddItem ("窒素爆弾")

  3. Dim a, b(4) As String Dim i As Integer a = ListBox1.Value'左のリストボックスで選択されている項目名 '生物学用語 If a = "A.オリゼー" Then b(1) = "学名:Aspergillus oryzae" b(2) = "和名:ニホンコウジカビ" b(3) = "澱粉を糖に分解する。" b(4) = "日本酒を作るときにかもしまくり" End If If a = "C.トリコイデス" Then b(1) = "学名:Cladosporium trichoides" b(2) = "和名:クラドスポリウム" b(3) = "お風呂の黒ずみの原因。" b(4) = "アニメではムーディ勝山が声を担当" End If If a = "A.アセチ" Then b(1) = "学名:Acetobacter aceti" b(2) = "和名:酢酸菌" b(3) = "ビールや日本酒を酢に変える。" b(4) = "醸造酒をかもすぞー!" End If '化学用語 If a = "錬金術" Then b(1) = "Alchemy" b(2) = "化学(Chemistry)の語源。" b(3) = "鉛等の卑金属から金等の貴金属を創る学問。" b(4) = "最新科学ではこれも可能だったり。" End If ※ListBox1_Clickの  イベントプロシージャに記述

  4. If a = "ポリウォーター" Then b(1) = "1966年にソ連で発見された。" b(2) = "水分子が重合しており、通常の水と物性が異なる。" b(3) = "新しい工業に発展すると期待されたが・・・" b(4) = "実はただの不純物による誤確認だった。" End If If a = "窒素爆弾" Then b(1) = "窒素を1700℃、110万気圧で圧縮すると" b(2) = "ポリ窒素になると言われ、原爆を上回る爆弾になる。" b(3) = "現在の科学では、作製は不可能。" b(4) = "エヴァンゲリオンを始め、多くのSFで登場する。" End If '物理学用語 If a = "青方偏移" Then b(1) = "英単語:blueshift" b(2) = "光のドップラー効果で、近づく物体が青く見える現象。" b(3) = "分光学では、短波長シフトのことを指す。" b(4) = "" End If If a = "ワープ" Then b(1) = "空間の歪みを利用した超光速移動。" b(2) = "SFではほぼ必ず出てくる。" b(3) = "空間歪曲に莫大なエネルギーが必要なため、" b(4) = "実際は不可能とされている。" End If If a = "バリヤー" Then b(1) = "英単語:varrier、deflector shield(偏向シールド)" b(2) = "量子ビームや重力場などにより、主に物理的攻撃を遮断。" b(3) = "SFではほぼ必須の技術。" b(4) = "なぜか音を立てて割れる。" End If 続き

  5. ListBox2.Clear For i = 1 To 4 ListBox2.AddItem (b(i)) Next 続き

  6. アイデア紹介 情報の蓄積と検索を主としたもの データベース系プログラムの場合、情報の視認性や検索のしやすさ、 データの量や質などが重要となる場合が多い 人物系 スポーツ系 ゲーム、漫画系 b = TextBox1.Text If b = "ルフィ" Or b = "モンキー・D・ルフィ" Then ・・・・ If b = "ゾロ" Or b = "ロロノア・ゾロ" Then Cells(2, 2).Value = "剣士"  ・  ・  ・

  7. 科学系 GotFocusイベントプロシージャ テキストボックスを使おうとしたときに実行される Private Sub TextBox1_GotFocus() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" End Sub クイズ・テスト系

  8. 時間割検索 Cells(11, 3).Value = "" Dim a As String Dim b As String a = TextBox1.Text b = TextBox2.Text Dim y As Integer, x As Integer '今日のプロ演の応用 Dim s As String x = 8 '月~金以外はH列 If a = "月" Then x = 3 '月曜日ならC列 If a = "火" Then x = 4 '火曜日ならD列 If a = "水" Then x = 5 '水曜日ならE列 If a = "木" Then x = 6 '木曜日ならF列 If a = "金" Then x = 7 '金曜日ならG列 If x < 8 And y > 0 Then '月~金ならばxが8以下になる s = Cells(y + 2, x).Value Cells(12, 3).Value = s End If 単位確認 視線とマウスカーソルを誘導するインターフェイス

  9. 演算機能を利用したもの 演算系のプログラムの場合、計算式の正確さと入力のしやすさ、 半自動入力などのインターフェイスが重要視される場合が多い。 家計簿 計算機 BMI ・・・毎年俺をキョーフのどん底に・・・

  10. じゃんけんゲーム 乱数をうまく使った例 統計学の系統樹的手法 情報数学的手法 a 自分の手 b コンピュータ(乱数1:グー,2:チョキ,3:パー) b = Int(Rnd() * 3) + 1 judge = b - a '勝ち負け判定用データ作成 If Abs(judge) > 1 Then judge = -judge / 2 If judge = 1 ThenMsgBox "あなたの勝ち!" If judge = 0 ThenMsgBox "あいこ!" If judge = -1 ThenMsgBox "あなたの負け!" a = ListBox1.Value If a = "グー" Then If b = 1 Then Cells(8, 4).Value = "Drow" If b = 2 Then Cells(8, 4).Value = "You win !!" If b = 3 Then Cells(8, 4).Value = "You lose " End If If a = "チョキ" Then If b = 1 Then Cells(8, 4).Value = "You lose " If b = 2 Then Cells(8, 4).Value = "Drow" If b = 3 Then Cells(8, 4).Value = "You win !!" End If If a = "パー" Then If b = 1 Then Cells(8, 4).Value = "You win !!" If b = 2 Then Cells(8, 4).Value = "You lose " If b = 3 Then Cells(8, 4).Value = "Drow" End If a(自分)とb(com)による変数judgeと勝敗の関係 judgeの絶対値が1より大きいとき、半分にして符号を 反転すれば、負け:-1、勝ち:1とシンプルになる

  11. Variantの上手な使い方の例 Dim c As Variant c = InputBox("炭素原子(C)の個数を入力してください。", "分子量計算") If c = "n" Then Cells(5, 1).Value = ChrW(&H250F) & " H" Cells(6, 1).Value = ChrW(&H2542) & " C " & ChrW(&H2500) Cells(7, 1).Value = ChrW(&H2517) & " H" Cells(5, 2).Value = "H " & ChrW(&H2513) Cells(6, 2).Value = "C " & ChrW(&H2542) Cells(7, 2).Value = "H " & ChrW(&H251B) & "n" Cells(1, 1).Value = "炭素:n個" Cells(1, 2).Value = "水素:2n+2個" Cells(3, 1).Value = "ポリエチレン" GoTo kakunin End If  ・  ・  ・ If h = c * 2 + 2 And o = 0 And n = 0 Then ・・・・・・・ If c = 6 And h = 6 And o = 0 And n = 0 Then ・・・・・ 入力時に「n」を入れると、 ポリエチレンの一般式を表示する。 炭素数を入れると、 通常通り構造式を描いて、 特定の分子の場合は分子名を表示。 記号の漢字コード マックでは使えないが、 通常表示できない記号 を表示できる。 プログラムからExcelの機能を使う =A2*12+B2+C2*16+D2*14 Range("E2").Select ActiveCell.FormulaR1C1 = "=RC[-4]*12+RC[-3]+RC[-2]*16+RC[-1]*14" マクロの記録を使って、「E2セルに、『=A2*12+B2+C2*16+D2*14』を表示するプログラムを 入れることで、分子量計算をExcelに任せる。 Cells(2, 5).Value = "=A2*12+B2+C2*16+D2*14" とプログラム内に記述しても同じ動きをする。

  12. For a = 2 To 18 If Cells(2, a) = "○" And Cells(3, a) = "○" Then Cells(4, a).Value = "◎" If Cells(2, a) = "○" And Cells(3, a) = "-" Then Cells(4, a).Value = "○"  ・  ・  ・ If Cells(2, a) = "-" And Cells(3, a) = "" Then Cells(4, a).Value = "-" If Cells(3, a) = "×" Then Cells(4, a).Value = "×" If Cells(2, a) = "×" Then Cells(4, a).Value = "×" Next タイプ1とタイプ2の 組み合わせで 弱点を決定・表示 シンプルで動作がわかりやすいが、 記号が増えるとIf文が大幅に増える For a = 2 To 18 'B列からR列をスキャン c = 0 For b = 2 To 3 '2行(タイプ1)から3行(タイプ2)をスキャン d = Cells(b, a).Value If d = "○" Then c = c - 1 If d = "△" Then c = c + 1 If d = "▲" Then c = c + 2 If d = "×" Then c = 100 Next If c = -2 Then d = "◎" '超弱点 If c = -1 Then d = "○" '弱点 If c = 0 Then d = "-" '普通 If c = 1 Then d = "△" '得意 If c = 2 Then d = "▲" '超得意 If c > 10 Then d = "×" '無効化 Cells(4, a).Value = d Next 返信レポートの改良案 シンプルだが、動作を理解するのに プログラムを読解する必要がある。 ただし、記号が増えてもプログラムは 数行しか増えず、汎用性が高い

More Related