Imports System
Module Program
Class elem
Public Property Ope As String
Dim a As String = _Ope
Public Property Lve As Integer
Dim b As Integer = _Lve
End Class
Sub Main(args As String())
Dim a As New elem
a.Ope = "100"
a.Lve = 0
Dim b As New elem With {.Ope = "+", .Lve = 1}
Dim c As New elem With {.Ope = "*", .Lve = 2}
Dim elemstack As New Stack
Dim w As elem
elemstack.Push(a)
elemstack.Push(b)
elemstack.Push(c)
Do While elemstack.Count > 0
w = elemstack.Pop
Console.Write(w.Ope + ", ")
Console.WriteLine(w.Lve)
Loop
Console.WriteLine("Hello World!")
End Sub
End Module
投稿者: isamrx73
Imports System
Module Program
Class elem
Private _ope As String
Private _lve As Integer
Public Property Ope() As String
Get
Return _ope
End Get
Set(value As String)
_ope = value
End Set
End Property
Public Property Lve() As Integer
Get
Return _lve
End Get
Set(value As Integer)
_lve = value
End Set
End Property
End Class
Sub Main(args As String())
Dim a As New elem
a.Ope = "100"
a.Lve = 0
Dim b As New elem With {.Ope = "+", .Lve = 1}
Dim c As New elem With {.Ope = "*", .Lve = 2}
Dim elemstack As New Stack
Dim w As elem
elemstack.Push(a)
elemstack.Push(b)
elemstack.Push(c)
Do While elemstack.Count > 0
w = elemstack.Pop
Console.Write(w.Ope + ", ")
Console.WriteLine(w.Lve)
Loop
Console.WriteLine("Hello World!")
End Sub
End Module
Imports System
Module Program
Class elem
Public ope As String
Public lev As Integer
End Class
Sub Main(args As String())
Dim inpstr As String = "6.1 + 5.2 * 4.3 - 3.4 / 2.5 * 1.6 "
Dim rpnstr As String = ""
Dim opeStack As New Stack
Dim aelem As New elem
While True
If inpstr.Length = 0 Then
GoTo owari
End If
Dim fSpacePosition As Integer = inpstr.IndexOf(" ")
Dim fstr As String = inpstr.Substring(0, fSpacePosition)
Dim nstr As String = Strings.Right(inpstr, inpstr.Length - fSpacePosition - 1)
If Not (fstr = "+" Or fstr = "-" Or fstr = "*" Or fstr = "/") Then
'演算子以外の数値は出力する
rpnstr += fstr + " "
Else
If opeStack.Count >= 1 Then
Dim wope As elem = opeStack.Peek
Dim currentlev As Integer
Select Case fstr
Case "*" : currentlev = 2
Case "/" : currentlev = 2
Case "+" : currentlev = 1
Case "-" : currentlev = 1
Case Else : currentlev = 0
End Select
Do While wope.lev >= currentlev And opeStack.Count >= 1
rpnstr += wope.ope + " "
opeStack.Pop()
If opeStack.Count > 0 Then
wope = opeStack.Peek
End If
Loop
Dim belem As New elem
belem.ope = fstr
belem.lev = currentlev
opeStack.Push(belem)
Else
'最初のスタックへの積上げ
If fstr = "+" Or fstr = "-" Then
aelem.lev = 1
Else
aelem.lev = 2
End If
aelem.ope = fstr
opeStack.Push(aelem)
End If
End If
inpstr = nstr
End While
owari:
Dim welem As elem
Do While opeStack.Count > 0
welem = opeStack.Pop
rpnstr += welem.ope + " "
Loop
Console.WriteLine(rpnstr)
Console.WriteLine("Hello World!")
End Sub
End Module
Imports System
Module Program
Class elem
Public ope As String
Public lev As Integer
End Class
Sub Main(args As String())
Dim a As New elem With {.ope = "100", .lev = 0}
Dim b As New elem With {.ope = "+", .lev = 1}
Dim elemstack As New Stack
Dim w As elem
elemstack.Push(a)
elemstack.Push(b)
Do While elemstack.Count > 0
w = elemstack.Pop
Console.Write(w.ope + ", ")
Console.WriteLine(w.lev)
Loop
Console.WriteLine("Hello World!")
End Sub
End Module
Imports System
Module Program
Sub Main(args As String())
Dim rpnstr As String = "6.1 5.2 4.3 * + 3.4 2.5 / 1.6 * - "
Dim opeStack As New Stack
While True
If rpnstr.Length = 0 Then
GoTo owari
End If
Dim fSpacePosition As Integer = rpnstr.IndexOf(" ")
Dim fstr As String = rpnstr.Substring(0, fSpacePosition)
Dim nstr As String = Strings.Right(rpnstr, rpnstr.Length - fSpacePosition - 1)
If fstr = "+" Or fstr = "-" Or fstr = "*" Or fstr = "/" Then
Dim y As Double = CDbl(opeStack.Pop)
Dim x As Double = CDbl(opeStack.Pop)
Select Case fstr
Case "+" : opeStack.Push(CStr(x + y))
Case "-" : opeStack.Push(CStr(x - y))
Case "*" : opeStack.Push(CStr(x * y))
Case "/" : opeStack.Push(CStr(x / y))
End Select
Else
opeStack.Push(fstr)
End If
rpnstr = nstr
End While
owari:
Console.WriteLine(opeStack.Pop)
Console.WriteLine("Hello World!")
End Sub
End Module
カテゴリー
逆ポーランド記法の計算式
Imports System
Module Program
Sub Main(args As String())
Dim rpnstr As String
Dim rpnary() As String
Dim ans As Double
rpnstr = "6.1 5.2 4.3 * + 3.4 2.5 / 1.6 * - "
While True
rpnstr = RTrim(rpnstr)
rpnary = rpnstr.Split(" ")
If rpnary.Length = 1 Then
ans = rpnary(0)
GoTo owari
End If
Dim i As Integer = 0
While True
If rpnary(i) = "+" Or rpnary(i) = "-" Or rpnary(i) = "*" Or rpnary(i) = "/" Then
GoTo mikke
End If
i += 1
End While
mikke:
Dim a As Double
Dim b As Double
a = CDbl(rpnary(i - 2))
b = CDbl(rpnary(i - 1))
If rpnary(i) = "+" Then
rpnary(i - 2) = a + b
ElseIf rpnary(i) = "-" Then
rpnary(i - 2) = a - b
ElseIf rpnary(i) = "*" Then
rpnary(i - 2) = a * b
Else
rpnary(i - 2) = a / b
End If
rpnary(i - 1) = ""
rpnary(i) = ""
rpnstr = ""
Dim j As Integer = 0
For j = 0 To i - 2 - 1
rpnstr += rpnary(j) + " "
Next
rpnstr += CStr(rpnary(i - 2)) + rpnary(i - 1) + rpnary(i) + " "
For j = i + 1 To rpnary.Length - 1
rpnstr += rpnary(j) + " "
Next
End While
owari:
Console.WriteLine(ans)
Console.WriteLine("Hello World!")
End Sub
#include <stdio.h>
int main(){
puts("Hello");
return 0;
}
dim a as integer
a = 100
print a
dim a as integer
a = 100
print a
highlighting code blockを使ってますが、デフォルトでの設定以外では、free契約のWordPressでは出来ないようです。何故かというと、サーバーにアクセスできないようですので。その結果、Visual Basicでは使えないということです。別に試したところでは、VS2022以上の使用感は実現されていないようです。上に載せているように、コードだけであれば問題ないように思います。
カテゴリー
Pythonのソースをアップしてみる
import tkinter
# 解読関数
def decode_line(event):
global current_line, bgimg, lcharimg, ccharimg, rcharimg
if current_line >= len(scenario):
return;
# 1行読み込み
line = scenario[current_line]
current_line = current_line + 1
line = line.replace("\\n", "\n").strip()
params = line.split(" ")
# 分岐
if line[0] != "#":
message["text"] = line
return
elif params[0] == "#back":
canvas.delete("all")
bgimg = tkinter.PhotoImage(file=params[1])
canvas.create_image(450, 230, image=bgimg)
elif params[0] == "#putChar":
if params[2] == "L":
canvas.delete("left")
lcharimg = tkinter.PhotoImage(file=params[1])
canvas.create_image(200, 160, image=lcharimg, tag="left")
elif params[2] == "R":
canvas.delete("right")
rcharimg = tkinter.PhotoImage(file=params[1])
canvas.create_image(700, 160, image=rcharimg, tag="right")
else:
canvas.delete("center")
ccharimg = tkinter.PhotoImage(file=params[1])
canvas.create_image(450, 160, image=ccharimg, tag="center")
elif params[0] == "#branch":
message.unbind("<Button-1>")
btn = tkinter.Button(text=params[2], width=20)
branch.append(btn)
btn["command"] = lambda : jump_to_line(int(params[1])-1)
btn.place(x=300, y=60+int(params[1])*60)
jumplabel.append(params[3])
if params[4] == "n":
return
elif params[0] == "#jump":
label = params[1].strip()
# ジャンプ先を探す
for l in range(len(scenario)):
if scenario[l].strip() == "## " + label:
current_line = l
decode_line(None)
return
elif params[0].strip() == "#end":
message["text"] = "終わり"
message.unbind("<Button-1>")
current_line = 999999999
# 再帰呼び出し
decode_line(None)
# ジャンプ関数
def jump_to_line(branchID):
global current_line
# ボタンを消す
for btn in branch:
btn.place_forget()
btn.destroy()
branch.clear()
label = jumplabel[branchID]
jumplabel.clear()
message.bind("<Button-1>", decode_line)
# ジャンプ先を探す
for l in range(len(scenario)):
if scenario[l].strip() == "## " + label:
current_line = l
decode_line(None)
return
# ウィンドウ作成
root = tkinter.Tk()
root.title("よろしくアドベンチャー")
root.minsize(900, 460)
root.option_add("*font", ["メイリオ", 14])
# キャンバス作成
canvas = tkinter.Canvas(width=900, height=460)
canvas.place(x=0, y=0)
# メッセージエリア
message = tkinter.Label(width=70, height=5, wraplength=840,
bg="white", justify="left", anchor="nw")
message.place(x=28, y=284)
message["text"] = "クリックしてスタート"
# ファイル読み込み
scenario = []
file = open("img8/scenario.txt", "r", encoding="utf-8")
while True:
line = file.readline()
scenario.append(line)
if not line:
file.close()
break
# 現在の行数
current_line = 0
# イベント設定
message.bind("<Button-1>", decode_line)
# 画像
bgimg = None
lcharimg = None
ccharimg = None
rcharimg = None
# 選択肢
branch = []
jumplabel = []
root.mainloop()
カテゴリー
gooブログバックアップデータの活用
Sub BlogBKDateToExcel()
Dim work As String, work2 As String
Dim inWord(10) As String
Dim i As Integer, j As Integer, k As Integer
Dim w1 As Integer, w2 As Integer
Dim ans As String
Dim ws0 As String
Dim pattern(10) As String
pattern(1) = "AUTHOR:"
pattern(2) = "TITLE:"
pattern(3) = "DATE:"
pattern(4) = "PRIMARY CATEGORY:"
pattern(5) = "STATUS:"
pattern(6) = "ALLOW COMMENTS:"
pattern(7) = "CONVERT BREAKS:"
pattern(8) = "-----"
pattern(9) = "BODY:"
pattern(10) = "--------"
Call HeaderPrint(pattern)
i = 1
Worksheets("sheet1").Activate 'ワークシートは1とします
Open "d:\blog\blogbk15-21.txt" For Input As #1 'バックアップファイルを展開してもの
Do Until EOF(1)
For k = 1 To 9
ans = ""
Input #1, work
NyuryokuPass:
If StrComp(work, pattern(9)) = 0 Then 'BODYの場合
Do
Input #1, work2
ans = ans + work2 '終了でない時は、読み込んだデーに加える
Loop While StrComp(work2, pattern(10)) <> 0 '終了でないうちは続けるpattern(10)はブログの区切り
inWord(k) = ans
Else 'BODY以外の処理
If StrComp(work, pattern(8)) <> 0 Then '-----は無視する。前回データを格納に行きます
w1 = InStr(work, ":")
ws0 = Mid(work, 1, w1)
ans = Right(work, Len(work) - Len(pattern(k)) - 1) 'TITLEの一番最初に読み込んだ処理
Do 'TITLEの読込が最後まで行くの行かないのか?
Input #1, work2
If StrComp(work2, pattern(8)) = 0 Then
inWord(k) = ans
k = k + 1
work = work2
GoTo NyuryokuPass
Else
w2 = InStr(work2, ":") '入力が途中で終わっているか?
If w2 = 0 Then '入力が途中、TITLEに半角","が入っている時
ans = ans + work2 + "、" '半角,を全角、で置換え
Else
inWord(k) = ans
k = k + 1
work = work2
GoTo NyuryokuPass
End If
End If
Loop While w2 = 0 '"DATE:"が出てくるまで、続ける
inWord(k) = ans '読み込んだデータがpattern(8)の時、前回データを格納します
End If
End If
Next k
i = i + 1
w0 = 0
For j = 1 To 9
If j = 9 Then
w0 = -1
End If
If j >= 4 Then
Cells(i, j + 2 + w0).Value = inWord(j)
Else
Cells(i, j).Value = inWord(j)
End If
Next j
Input #1, work
Loop
Close #1
Call ハイパーリンク作成
Call 表全体を検索
MsgBox "処理を終わります"
End Sub
Sub HeaderPrint(patterns() As String)
Cells(1, 1) = patterns(1)
Cells(1, 2) = patterns(2)
Cells(1, 3) = patterns(3)
Cells(1, 4) = "WorkDate"
Cells(1, 5) = "HyperLink"
Cells(1, 6) = patterns(4)
Cells(1, 7) = patterns(5)
Cells(1, 8) = "Comments"
Cells(1, 9) = "Breaks"
Cells(1, 10) = patterns(9)
End Sub
Sub ハイパーリンク作成()
Dim i As Integer
Dim last As Integer
last = Cells(2, 1).End(xlDown).Row
For i = 2 To last
Range("d" & i).FormulaR1C1 = "=TEXT(RC[-1], ""yyyymmdd"")"
ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 5), _
Address:="https://blog.goo.ne.jp/" + Cells(i, 1) + "/d/" + Cells(i, 4), _
TextToDisplay:="https://blog.goo.ne.jp/isamrx72/d/" + Cells(i, 4)
Next
'MsgBox "ハイパーリンクの作成終了"
End Sub
Sub テキストボックスを作る()
'
' テキストボックスを作る Macro
'
' Keyboard Shortcut: Ctrl+t
'
Worksheets("sheet1").Activate
Dim i As Long
Dim j As Long
Dim 範囲 As Range
Dim ws As Worksheet
Set ws = ActiveSheet
i = ActiveCell.Row
j = ActiveCell.Column
Set 範囲 = Range(Cells(i + 1, j), Cells(i + 6, j + 5))
Dim shp As Shape
Set shp = ws.Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, _
Left:=範囲.Left, Top:=範囲.Top, _
Width:=範囲.Width, Height:=範囲.Height)
shp.TextFrame.Characters.Font.Size = 10
Dim chars As Characters
Set chars = shp.TextFrame.Characters
chars.Text = Cells(i, j).Value
chars.Font.Color = RGB(255, 0, 0)
End Sub
Sub テキストボックスの全削除()
'
' テキストボックスの全削除 Macro
'
' Keyboard Shortcut: Ctrl+k
'
Worksheets("sheet1").Activate
Dim sp As Shape
For Each sp In ActiveSheet.Shapes
sp.Delete
Next
End Sub
Sub 表全体を検索()
'
' 表全体を検索 Macro
'
' Keyboard Shortcut: Ctrl+z
'
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.AutoFilter
Range("A1").Select
End Sub
多分、コード自体は良いと思いますが、テキストの色付けがおかしいようです。VBAには対応してないのかも?
//#include <condefs>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;
#pragma hdrstop
int main(int argc, char** argv)
{
char buff[81]; //漢字大丈夫?
ifstream infile;
infile.open("readfile.cpp");
if (!infile) return 0;
while (!infile.eof()) {
infile.getline(buff, sizeof(buff));
cout << buff << endl;
}
infile.close();
cout << endl << "Press any key to continue...";
//getch();
return 0;
}
上はC++Builder入門のサンプルコード。自分自身を表示します。
/*
Chotto.c multifile cat. procedures
Designed & created by N.Mita 1986/05/28 Copyright Core Dump Co,.Ltd.
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define CLS cls()
//画面を消去する関数を呼ぶマクロ
#define MAXFILES 128 //このプログラムで扱えるファイル数の最大値256
#define MAXLINES 256 //このプログラムで扱える1行の文字数の最大値
static char file_name[MAXFILES][40]; //ファイル名を入れておくバッファ
FILE* fp; //ファイル構造体へのポインタ
void cls()
{ //・・画面を消去する関数(どの処理系でも対応できるように、 25 行空行を送るだけにしてある)
int i;
for (i = 0; i < 25; ++i) printf("\n");
}
int open_file(fname) //ファイルをオープンする関数
char fname[];
{
if (NULL == (fp = fopen(fname, "r")))
return(0);
else
return(1);
}
void close_file() //ファイルをクローズする関数
{
fclose(fp);
}
void cat_file(line) // ......... ファイルの内容を指定行数だけ表示する関数
int line; /* number of display lines*/
{
int i, j;
char line_buff[MAXLINES]; /* display line-buffer */
for (i = 0; i < line; ++i) //....... 1行を処理するループ
{
if (NULL == fgets(line_buff, MAXLINES, fp)) // 1行を読み込み、エラーが起きた
{ //かどうか判断する
if (feof(fp)) break; //ファイルの終わりならば for ループを抜ける
if (ferror(fp))
{
printf(">>>>>>> Read-ERROR on FILE <<<<<<<\n");
break;
}
} //エラーであれば 処理を中断して終了
for (j = 0; j < MAXLINES; ++j) //......... ファイルから読み込んだ行を表示する
{
if ((int)NULL == line_buff[j]) break; //読めない文字があった場合は、 .ピリオド
if ((isspace(line_buff[j])) || (' ' <= line_buff[j]))
putchar(line_buff[j]);
else
putchar('.');
}
}
}
int disp_1file(fname, n) //指定されたファイルを表示する関数
char fname[]; /* file-names for display */
int n; /* number of display-lines */
{
if (!open_file(fname))
{
printf("******* Cannot open file: %20s ******\n", fname);
return(0);
}
else
{
printf("-------- FILE : %20s --------\n", fname);
cat_file(n);
printf("\n\n");
}
close_file();
return (1);
}
void disp_file(m, n) //・指定された複数ファイルを表示する関数
int m; /* Number of files */
int n; /* Number of lines */
{
int i; char dummy[40];
for (i = 0; i < m; ++i)
{
disp_1file(&file_name[i][0], n);
puts("Press return...........");
gets(dummy);
}
}
int input_file() //ファイル名の入力関数
{
int i;
CLS;
for (i = 0; i < MAXFILES; ++i)
{
printf("%5d: FILE-NAME=", i + 1);
gets(&file_name[i][0]);
if (0 >= strlen(&file_name[i][0])) break;
}
return(i);
}
int input_line() //表示行数の入力関数
{
char i_str[40];
printf(" : LINES ? = ");
gets(i_str);
return(atoi(i_str));
}
int main() //・・・・・・メインの関数. できるだけシンプルになっていることが望ましい
{
int i, j;
if (0 >= (i = input_file())) //.....・ファイル名の入力
{
printf("******* No files *******\n");
exit(0);
}
else
{
if (0 >= (j = input_line())) // 表示行数の入力
{
printf("******* No lines *******¥n");
exit(0);
}
disp_file(i, j); //......... 実際の処理
}
printf("------- Complete. -------\n"); //作業終了の表示
return 0;
}
上は三田典玄さんのサンプルコード。表示するファイル名をstaticで確保してます。
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string.h>
using namespace std;
#pragma hdrstop
#define MAXFILES 5
#define MAXLINES 10
class FileNameArray
{
public:
FileNameArray();
~FileNameArray();
char* getFname() { return fname; }
void setFname(char* fn) { strcpy(fname, fn); }
private:
char fname[40];
};
FileNameArray::FileNameArray()
{
strcpy(fname, "end");
}
FileNameArray::~FileNameArray()
{
}
int InputFileName(FileNameArray* fnm[]) {
for (int i = 0; i < (MAXFILES - 1); i++) {
char w[40];
cout << i + 1 << " FileName: ";
cin >> w;
fnm[i]->setFname(w);
if (strcmp(w, "end") == 0) {
return -1;
}
}
return 0;
}
void PrintFileName(FileNameArray* fnm[]) {
for (int i = 0; i < MAXFILES - 1; i++) {
cout << i + 1 << " :FileName: ";
cout << fnm[i]->getFname() << endl;
if (strcmp(fnm[i]->getFname(), "end") == 0)
break;
}
}
int PrintFileStop(FileNameArray* ptr[]) {
char buff[81];
for (int i = 0; i < MAXFILES - 1; i++) {
ifstream infile;
char w[40];
int lcnt = 0;
strcpy(w, ptr[i]->getFname());
if (strcmp(w, "end") != 0) {
infile.open(w);
if (!infile) return -1;
while (!infile.eof()) {
infile.getline(buff, sizeof(buff));
cout << buff << endl;
lcnt++;
if (lcnt > MAXLINES)
break;
}
}
else {
infile.close();
break;
}
infile.close();
}
return 0;
}
int main(int argc, char** argv)
{
FileNameArray* fnab[MAXFILES];
for (int i = 0; i < (MAXFILES - 1); i++)
fnab[i] = new FileNameArray();
InputFileName(fnab);
char msg[40];
(PrintFileStop(fnab) != 0) ? (strcpy(msg, "異常")) : (strcpy(msg, "正常"));
cout << msg << "終了しました。";
cout << endl << "Press any key to continue...";
return 0;
}
上は見様見真似で弄り回した自分で書いたもの。ファイル名を入れておくところをclassで作って、mainに置いてます。それらはポインタの配列で、必要なルーティンへ渡します。PrintFileStopはほぼ、C++Builder入門のコードと同じです。