カレンダーを作成しているのですが...

ActiveBasicでのプログラミングでわからないこと、困ったことなどがあったら、ここで質問してみましょう(質問を行う場合は、過去ログやWeb上であらかじめ問題を整理するようにしましょう☆)。
メッセージ
作成者
エイチ
記事: 8
登録日時: 2005年10月16日(日) 22:57
お住まい: 神奈川県厚木市

カレンダーを作成しているのですが...

#1 投稿記事 by エイチ »

プログラム初心者のエイチと申します。ABはだいぶ前に窓の杜で知り、とりあえずダウンロードしましたがプログラムの仕方が分からず長いことそのままになっていました。先日、ひょんなことから祝日法が改正になり、4年後の9月に5連休が来るらしいことを知りました。そこで、ABを使ってカレンダーを作ってみることにしたのですが...。
VBの解説本を参考にしているのですが、メインのウィンドウに年と月の表示と、前の月と次の月にめくれるボタン、年を動かすスクロールボタン、そして日曜から土曜日の見出しと日付が入る可能性のある37個のstaticといろいろ用意しなければいけません。はじめは1つ1つウィンドウを作っていたのですが、ソースがぐちゃぐちゃで分かりづらくなったので、CreateWindowEx関数の引数を構造体の配列に書き換えたところで、""Type"の使い方が不正です"ということで動かなくなってしまいました。どうしてなんでしょう。
ちなみに、プロジェクトは使っていません。
konisi
記事: 893
登録日時: 2005年7月25日(月) 13:27
お住まい: 埼玉県東松山市
連絡する:

Re: カレンダーを作成しているのですが...

#2 投稿記事 by konisi »

私も暇だったので作ってみましたがどうでしょう?

コード: 全て選択


'ここから自作関数の定義
Function Sleep_IfFore()
	Do
		if GetForegroundWindow()=_PromptSys_hWnd then Exit Do
	Loop
End Function
Function PutKey$(ByRef C As Byte,ByRef S As Byte,ByRef A As Byte,ByRef R As Byte,ByRef L As Byte,ByRef H As Byte) As String
	C=0
	S=0
	A=0
	R=0
	L=0
	H=0
	Dim i,A$ As String
		For i=&h00 To &hf0
		if GetAsyncKeyState(i) And &h8000 Then
			Select Case i
				Case 1
					L=1
				Case 2
					R=1
				Case 4
					H=1
				Case 16
					S=1
				Case 17
					C=1
				Case 18
					A=1
				Case 160
					if S=1 then S=2
				Case 162
					if C=1 then C=2
				Case 164
					if A=1 then A=2
				Case Else
					A$=Chr$(i)
			End Select
		Endif
	Next I
	if S=1 then S=0
	if C=1 then C=0
	if A=1 then A=0
	if S=2 then S=1
	if C=2 then C=1
	if A=2 then A=1
	PutKey$=A$
End Function
Function OnMouse(ByRef X As DWord,ByRef Y As DWord) As Double
	Dim A As POINTAPI
	Dim B As RECT
	GetWindowRect(_PromptSys_hWnd,B)
	GetCursorPos(A)
	X=A.x-B.left-6'それぞれ枠の大きさを考えてマイナスにする
	Y=A.y-B.top-31
	OnMouse=-1
End Function
Type FuncKey
	A As Byte
	C As Byte
	S As Byte
End Type
Type FuncMouse
	L As Byte
	R As Byte
	H As Byte
End Type
'ここまで。PutKey$関数は別の自作プログラムから引用した為多少の無駄があるがご了承。
'ここからメイン
#N88BASIC
Dim Mouse_x As DWord
Dim Mouse_y As DWord
Dim MouseKey As FuncMouse
Dim DoubleKey As FuncKey
Dim Key$ As String
Dim I As Long
Dim D As Long,DN As Long
Dim st As SYSTEMTIME
Dim Month_Day
Dim Flag_Input As Long

GetLocalTime(st)

'現在の日付と曜日からその月の開始する曜日を計算
st.wDay=(st.wDay-st.wDayOfWeek+5) Mod 7
if st.wDay=0 then st.wDay=7
*START
DN=1

'その月の日数を計算
if st.wMonth=1 then Month_Day=31
if st.wMonth=2 then
	if st.wYear Mod 4=0 then'4で割れると閏年
		Month_Day=29
	Else
		Month_Day=28
	Endif
	if st.wYear Mod 100=0 then'ただし100で割れると閏年としない
		Month_Day=28
	Endif
	if st.wYear Mod 400=0 then'ただし400で割れれば閏年とする
		Month_Day=29
	Endif
End If
if st.wMonth=3 then Month_Day=31
if st.wMonth=4 then Month_Day=30
if st.wMonth=5 then Month_Day=31
if st.wMonth=6 then Month_Day=30
if st.wMonth=7 then Month_Day=31
if st.wMonth=8 then Month_Day=31
if st.wMonth=9 then Month_Day=30
if st.wMonth=10 then Month_Day=31
if st.wMonth=11 then Month_Day=30
if st.wMonth=12 then Month_Day=31

'ここから表示
Cls 3
Locate 7,0
Print "先月"
Locate 21,0
Print st.wYear;"年";st.wMonth;"月"
Locate 47,0
Print "次月"
Locate 7,2
Print "日     月     火     水     木     金     土"
For D=st.wDay To 7
	Locate D*7,4
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,7
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,10
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,13
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	if DN>Month_Day then Exit For
	Locate D*7,16
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	if DN>Month_Day then Exit For
	Locate D*7,19
	Print DN
	DN=DN+1
Next D
'ここまで
'ここから入力待ち
Do'左ボタンがクリックされた場合に抜け出せる場合があるループ
	Sleep_IfFore()'フォアグランドウインドウではない場合にクリックに反応しない
	Key$=PutKey$(DoubleKey.C,DoubleKey.S,DoubleKey.A,MouseKey.R,MouseKey.L,MouseKey.H)
	OnMouse(Mouse_x,Mouse_y)
	Flag_Input=0
	if MouseKey.L=1 then Flag_Input=1
	if Mouse_x>53 then Flag_Input=Flag_Input+1
	if Mouse_x<86 then Flag_Input=Flag_Input+1
	if Mouse_y>-1 then Flag_Input=Flag_Input+1
	if Mouse_y<16 then Flag_Input=Flag_Input+1
	if Flag_Input=5 then
		st.wMonth=st.wMonth-1
		if st.wMonth=0 then st.wMonth=12:st.wYear=st.wYear-1

		if st.wMonth=1 then Month_Day=31
		if st.wMonth=2 then
			if st.wYear Mod 4=0 then
				Month_Day=29
			Else
				Month_Day=28
			Endif
			if st.wYear Mod 100=0 then
				Month_Day=28
			Endif
			if st.wYear Mod 400=0 then
				Month_Day=29
			Endif
		End If
		if st.wMonth=3 then Month_Day=31
		if st.wMonth=4 then Month_Day=30
		if st.wMonth=5 then Month_Day=31
		if st.wMonth=6 then Month_Day=30
		if st.wMonth=7 then Month_Day=31
		if st.wMonth=8 then Month_Day=31
		if st.wMonth=9 then Month_Day=30
		if st.wMonth=10 then Month_Day=31
		if st.wMonth=11 then Month_Day=30
		if st.wMonth=12 then Month_Day=31

		st.wDay=(st.wDay-Month_Day+35) Mod 7
		if st.wDay=0 then st.wDay=7
		Exit Do
	End if

	Flag_Input=0
	if MouseKey.L=1 then Flag_Input=1
	if Mouse_x>373 then Flag_Input=Flag_Input+1
	if Mouse_x<406 then Flag_Input=Flag_Input+1
	if Mouse_y>-1 then Flag_Input=Flag_Input+1
	if Mouse_y<16 then Flag_Input=Flag_Input+1
	if Flag_Input=5 then
		st.wDay=(st.wDay+Month_Day) Mod 7
		if st.wDay=0 then st.wDay=7
		st.wMonth=st.wMonth+1
		if st.wMonth=13 then st.wMonth=1:st.wYear=st.wYear+1
		Exit Do
	Endif

Loop
Do'押しっぱなしの場合にせきとめるループ
	Key$=PutKey$(DoubleKey.C,DoubleKey.S,DoubleKey.A,MouseKey.R,MouseKey.L,MouseKey.H)
	if MouseKey.L=0 then Exit Do
Loop
'ここまで
goto *START
コードに不備がありましたらエイチさん、イグトランス様方、ご指摘願います。
今のところ起動に時間がかかるのが一つの難点ですかね(汗
konisi
記事: 893
登録日時: 2005年7月25日(月) 13:27
お住まい: 埼玉県東松山市
連絡する:

後日談

#3 投稿記事 by konisi »

ちょっと改造して西暦1年のカレンダー出してみたところ、次のことがわかりました。
西暦1年1月1日は月曜日
西暦1年12月25日は火曜日
まさか・・・西暦1年1月1日が週の始めでもあったとは・・・
ちなみに、西暦1年1月1日以前のカレンダーは、プログラムの機能上日付狂うと思います。(実際に狂っているかどうかなんてわかりゃしませんが。)
また、使用バージョンは4.10.01です。
以上、追記でした。
イグトランス
記事: 899
登録日時: 2005年5月31日(火) 17:59
お住まい: 東京都
連絡する:

#4 投稿記事 by イグトランス »

しかし西暦1年では今のグレゴリオ暦(1年が365日で4年に1度の閏年と100年400年の例外)が使われていないので、
グレゴリオ暦で計算しても1年1月1日がちょうど月曜日になるというのはすごい偶然です。
konisi
記事: 893
登録日時: 2005年7月25日(月) 13:27
お住まい: 埼玉県東松山市
連絡する:

#5 投稿記事 by konisi »

あ、そうでしたね。グレゴリオ暦は確か1582年10月から使われるようになって・・・
その前から使われていたのはユウリス暦とかいいましたっけ?
4年に一度の閏年に例外が無いんですよね、確か。
それを考えると凄い偶然ですね(汗
konisi
記事: 893
登録日時: 2005年7月25日(月) 13:27
お住まい: 埼玉県東松山市
連絡する:

二ヶ国語対応版

#6 投稿記事 by konisi »

相当暇だったので二ヶ国語対応にしてみました。
海外のWinOSで動くかどうかは問題外で、表記だけを英語にも出来るようにしたってだけですが。
もうちょっと小分け関数作ったほうがよかったなー。

コード: 全て選択


'ここから自作関数の定義
Function Sleep_IfFore()
	Do
		if GetForegroundWindow()=_PromptSys_hWnd then Exit Do
	Loop
End Function
Function PutKey$(ByRef C As Byte,ByRef S As Byte,ByRef A As Byte,ByRef R As Byte,ByRef L As Byte,ByRef H As Byte) As String
	C=0
	S=0
	A=0
	R=0
	L=0
	H=0
	Dim i,A$ As String
		For i=&h00 To &hf0
		if GetAsyncKeyState(i) And &h8000 Then
			Select Case i
				Case 1
					L=1
				Case 2
					R=1
				Case 4
					H=1
				Case 16
					S=1
				Case 17
					C=1
				Case 18
					A=1
				Case 160
					if S=1 then S=2
				Case 162
					if C=1 then C=2
				Case 164
					if A=1 then A=2
				Case Else
					A$=Chr$(i)
			End Select
		Endif
	Next I
	if S=1 then S=0
	if C=1 then C=0
	if A=1 then A=0
	if S=2 then S=1
	if C=2 then C=1
	if A=2 then A=1
	PutKey$=A$
End Function
Function OnMouse(ByRef X As DWord,ByRef Y As DWord) As Double
	Dim A As POINTAPI
	Dim B As RECT
	GetWindowRect(_PromptSys_hWnd,B)
	GetCursorPos(A)
	X=A.x-B.left-6
	Y=A.y-B.top-31
	OnMouse=-1
End Function
Type FuncKey
	A As Byte
	C As Byte
	S As Byte
End Type
Type FuncMouse
	L As Byte
	R As Byte
	H As Byte
End Type
Function Eng$(Month As Long) As String
if Month=1 then Eng$="January"
if Month=2 then Eng$="February"
if Month=3 then Eng$="March"
if Month=4 then Eng$="April"
if Month=5 then Eng$="May"
if Month=6 then Eng$="June"
if Month=7 then Eng$="July"
if Month=8 then Eng$="August"
if Month=9 then Eng$="September"
if Month=10 then Eng$="October"
if Month=11 then Eng$="November"
if Month=12 then Eng$="December"
End Function
'ここまで。
'ここからメイン
#N88BASIC
Dim Mouse_x As DWord
Dim Mouse_y As DWord
Dim MouseKey As FuncMouse
Dim DoubleKey As FuncKey
Dim Key$ As String
Dim I As Long
Dim D As Long,DN As Long
Dim st As SYSTEMTIME
Dim Month_Day
Dim Flag_Input As Long
Dim A$ As String,TIME$ As String
Dim Lang As Long
Lang=1'1の時日本語、2の時英語
GetLocalTime(st)

'現在の日付と曜日からその月の開始する曜日を計算
st.wDay=(st.wDay-st.wDayOfWeek+5) Mod 7
if st.wDay=0 then st.wDay=7
*START_J

DN=1

'その月の日数を計算
if st.wMonth=1 then Month_Day=31
if st.wMonth=2 then
	if st.wYear Mod 4=0 then'4で割れると閏年
		Month_Day=29
	Else
		Month_Day=28
	Endif
	if st.wYear Mod 100=0 then'ただし100で割れると閏年としない
		Month_Day=28
	Endif
	if st.wYear Mod 400=0 then'ただし400で割れれば閏年とする
		Month_Day=29
	Endif
End If
if st.wMonth=3 then Month_Day=31
if st.wMonth=4 then Month_Day=30
if st.wMonth=5 then Month_Day=31
if st.wMonth=6 then Month_Day=30
if st.wMonth=7 then Month_Day=31
if st.wMonth=8 then Month_Day=31
if st.wMonth=9 then Month_Day=30
if st.wMonth=10 then Month_Day=31
if st.wMonth=11 then Month_Day=30
if st.wMonth=12 then Month_Day=31

'ここから表示
Cls 3
Locate 21,0
Print st.wYear;"年";st.wMonth;"月"
Locate 7,0
Print "先月"
Locate 47,0
Print "次月"
Locate 7,2
Print "日     月     火     水     木     金     土"
For D=st.wDay To 7
	Locate D*7,4
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,7
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,10
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,13
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	if DN>Month_Day then Exit For
	Locate D*7,16
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	if DN>Month_Day then Exit For
	Locate D*7,19
	Print DN
	DN=DN+1
Next D
Locate 8,21
A$="現在時刻:"+Date$()+"   "+TIME$
Print A$
Locate 0,23
Print "Altキーで表示言語切り替え"
Print "Ctrlキーで適用"
Print "It is a display language switch with the Alt key. "
Print "It applies with the Ctrl key. "
'ここまで
'ここから入力待ち
Do'左ボタンがクリックされた場合に抜け出せる場合があるループ
	Sleep_IfFore()'フォアグランドウインドウではない場合にクリックに反応しない
	Key$=PutKey$(DoubleKey.C,DoubleKey.S,DoubleKey.A,MouseKey.R,MouseKey.L,MouseKey.H)
	OnMouse(Mouse_x,Mouse_y)
	Flag_Input=0
	if MouseKey.L=1 then Flag_Input=1
	if Mouse_x>53 then Flag_Input=Flag_Input+1
	if Mouse_x<86 then Flag_Input=Flag_Input+1
	if Mouse_y>-1 then Flag_Input=Flag_Input+1
	if Mouse_y<16 then Flag_Input=Flag_Input+1
	if Flag_Input=5 then
		st.wMonth=st.wMonth-1
		if st.wMonth=0 then st.wMonth=12:st.wYear=st.wYear-1

		if st.wMonth=1 then Month_Day=31
		if st.wMonth=2 then
			if st.wYear Mod 4=0 then
				Month_Day=29
			Else
				Month_Day=28
			Endif
			if st.wYear Mod 100=0 then
				Month_Day=28
			Endif
			if st.wYear Mod 400=0 then
				Month_Day=29
			Endif
		End If
		if st.wMonth=3 then Month_Day=31
		if st.wMonth=4 then Month_Day=30
		if st.wMonth=5 then Month_Day=31
		if st.wMonth=6 then Month_Day=30
		if st.wMonth=7 then Month_Day=31
		if st.wMonth=8 then Month_Day=31
		if st.wMonth=9 then Month_Day=30
		if st.wMonth=10 then Month_Day=31
		if st.wMonth=11 then Month_Day=30
		if st.wMonth=12 then Month_Day=31

		st.wDay=(st.wDay-Month_Day+35) Mod 7
		if st.wDay=0 then st.wDay=7
		Exit Do
	End if

	Flag_Input=0
	if MouseKey.L=1 then Flag_Input=1
	if Mouse_x>373 then Flag_Input=Flag_Input+1
	if Mouse_x<406 then Flag_Input=Flag_Input+1
	if Mouse_y>-1 then Flag_Input=Flag_Input+1
	if Mouse_y<16 then Flag_Input=Flag_Input+1
	if Flag_Input=5 then
		st.wDay=(st.wDay+Month_Day) Mod 7
		if st.wDay=0 then st.wDay=7
		st.wMonth=st.wMonth+1
		if st.wMonth=13 then st.wMonth=1:st.wYear=st.wYear+1
		Exit Do
	Endif
	'ここから現在時刻の表示
	if Time$()<>TIME$ then
		Locate 8,21
		TIME$=Time$()
		A$="現在時刻:"+Date$()+"   "+TIME$
		Print A$
	End If
	if DoubleKey.A=1 then Lang=2
	if DoubleKey.C=1 then Exit Do
Loop
Do'押しっぱなしの場合にせきとめるループ
	Key$=PutKey$(DoubleKey.C,DoubleKey.S,DoubleKey.A,MouseKey.R,MouseKey.L,MouseKey.H)
	if MouseKey.L=0 then Exit Do
Loop
'ここまで
if Lang=1 then goto *START_J Else goto *START_E

*START_E

DN=1

'その月の日数を計算
if st.wMonth=1 then Month_Day=31
if st.wMonth=2 then
	if st.wYear Mod 4=0 then'4で割れると閏年
		Month_Day=29
	Else
		Month_Day=28
	Endif
	if st.wYear Mod 100=0 then'ただし100で割れると閏年としない
		Month_Day=28
	Endif
	if st.wYear Mod 400=0 then'ただし400で割れれば閏年とする
		Month_Day=29
	Endif
End If
if st.wMonth=3 then Month_Day=31
if st.wMonth=4 then Month_Day=30
if st.wMonth=5 then Month_Day=31
if st.wMonth=6 then Month_Day=30
if st.wMonth=7 then Month_Day=31
if st.wMonth=8 then Month_Day=31
if st.wMonth=9 then Month_Day=30
if st.wMonth=10 then Month_Day=31
if st.wMonth=11 then Month_Day=30
if st.wMonth=12 then Month_Day=31

'ここから表示
Cls 3
Locate 21,0
Print st.wYear;"/";Eng$(st.wMonth)
Locate 7,0
Print "Last"
Locate 47,0
Print "Next"
Locate 7,2
Print "Sun    Mon    Tue    Wed    Thu    Fri    Sat"
For D=st.wDay To 7
	Locate D*7,4
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,7
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,10
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	Locate D*7,13
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	if DN>Month_Day then Exit For
	Locate D*7,16
	Print DN
	DN=DN+1
Next D
For D=1 To 7
	if DN>Month_Day then Exit For
	Locate D*7,19
	Print DN
	DN=DN+1
Next D
Locate 8,21
A$="Now Time:"+Date$()+"   "+TIME$
Print A$
Locate 0,23
Print "Altキーで表示言語切り替え"
Print "Ctrlキーで適用"
Print "It is a display language switch with the Alt key. "
Print "It applies with the Ctrl key. "
'ここまで
'ここから入力待ち
Do'左ボタンがクリックされた場合に抜け出せる場合があるループ
	Sleep_IfFore()'フォアグランドウインドウではない場合にクリックに反応しない
	Key$=PutKey$(DoubleKey.C,DoubleKey.S,DoubleKey.A,MouseKey.R,MouseKey.L,MouseKey.H)
	OnMouse(Mouse_x,Mouse_y)
	Flag_Input=0
	if MouseKey.L=1 then Flag_Input=1
	if Mouse_x>53 then Flag_Input=Flag_Input+1
	if Mouse_x<86 then Flag_Input=Flag_Input+1
	if Mouse_y>-1 then Flag_Input=Flag_Input+1
	if Mouse_y<16 then Flag_Input=Flag_Input+1
	if Flag_Input=5 then
		st.wMonth=st.wMonth-1
		if st.wMonth=0 then st.wMonth=12:st.wYear=st.wYear-1

		if st.wMonth=1 then Month_Day=31
		if st.wMonth=2 then
			if st.wYear Mod 4=0 then
				Month_Day=29
			Else
				Month_Day=28
			Endif
			if st.wYear Mod 100=0 then
				Month_Day=28
			Endif
			if st.wYear Mod 400=0 then
				Month_Day=29
			Endif
		End If
		if st.wMonth=3 then Month_Day=31
		if st.wMonth=4 then Month_Day=30
		if st.wMonth=5 then Month_Day=31
		if st.wMonth=6 then Month_Day=30
		if st.wMonth=7 then Month_Day=31
		if st.wMonth=8 then Month_Day=31
		if st.wMonth=9 then Month_Day=30
		if st.wMonth=10 then Month_Day=31
		if st.wMonth=11 then Month_Day=30
		if st.wMonth=12 then Month_Day=31

		st.wDay=(st.wDay-Month_Day+35) Mod 7
		if st.wDay=0 then st.wDay=7
		Exit Do
	End if

	Flag_Input=0
	if MouseKey.L=1 then Flag_Input=1
	if Mouse_x>373 then Flag_Input=Flag_Input+1
	if Mouse_x<406 then Flag_Input=Flag_Input+1
	if Mouse_y>-1 then Flag_Input=Flag_Input+1
	if Mouse_y<16 then Flag_Input=Flag_Input+1
	if Flag_Input=5 then
		st.wDay=(st.wDay+Month_Day) Mod 7
		if st.wDay=0 then st.wDay=7
		st.wMonth=st.wMonth+1
		if st.wMonth=13 then st.wMonth=1:st.wYear=st.wYear+1
		Exit Do
	Endif
	'ここから現在時刻の表示
	if Time$()<>TIME$ then
		Locate 8,21
		TIME$=Time$()
		A$="Now Time:"+Date$()+"   "+TIME$
		Print A$
	End If
	if DoubleKey.A=1 then Lang=1
	if DoubleKey.C=1 then Exit Do
Loop
Do
	Key$=PutKey$(DoubleKey.C,DoubleKey.S,DoubleKey.A,MouseKey.R,MouseKey.L,MouseKey.H)
	if MouseKey.L=0 then Exit Do
Loop
if Lang=2 then goto *START_E Else goto *START_J
どれだけ暇なんだろ。俺。
こういう改造しても意味無かったかな。
エイチ
記事: 8
登録日時: 2005年10月16日(日) 22:57
お住まい: 神奈川県厚木市

#7 投稿記事 by エイチ »

 konisi様、イグトランス様、お忙しい中大変ありがとうございました。参考にさせていただきます。
 昨日の質問の件につきましては解決しました。Function内でTypeしてました。
 また新たな質問なのですが、integer型を関数の引数の型に合わせるために、BytePtr型にするにはどうすればいいのでしょうか?その場合、元のinteger型の変数も計算に使えるようにしておきたいのですが。
 本当に初心者で質問の仕方も要領がよく分かっていないのでおかしな表現があると思いますが、参考になるようなものがあればご紹介いただけると助かります。
 よろしくお願いします。
konisi
記事: 893
登録日時: 2005年7月25日(月) 13:27
お住まい: 埼玉県東松山市
連絡する:

#8 投稿記事 by konisi »

>  konisi様、イグトランス様、お忙しい中大変ありがとうございました。参考にさせていただきます。
>  昨日の質問の件につきましては解決しました。Function内でTypeしてました。
>  また新たな質問なのですが、integer型を関数の引数の型に合わせるために、BytePtr型にするにはどうすればいいのでしょうか?その場合、元のinteger型の変数も計算に使えるようにしておきたいのですが。
>  本当に初心者で質問の仕方も要領がよく分かっていないのでおかしな表現があると思いますが、参考になるようなものがあればご紹介いただけると助かります。
>  よろしくお願いします。
そもそもinteger型とBytePtr型のサイズが違うので、意味が良く分かりにくいのですが・・・何の関数で使うのですか?
konisi
記事: 893
登録日時: 2005年7月25日(月) 13:27
お住まい: 埼玉県東松山市
連絡する:

#9 投稿記事 by konisi »

訂正、なんと言う名前の関数で使うのですか?
エイチ
記事: 8
登録日時: 2005年10月16日(日) 22:57
お住まい: 神奈川県厚木市

#10 投稿記事 by エイチ »

 言葉足らずですみません。CreateWindowEx関数の第3パラメータに使いたい(EDITで表示したいし、できるなら入力されたものをinteger型に変更したい)と思ったのですが...。自分の中では、ここに表示させたい西暦が表示されるようにしたいと思っています。
イグトランス
記事: 899
登録日時: 2005年5月31日(火) 17:59
お住まい: 東京都
連絡する:

#11 投稿記事 by イグトランス »

EditコントロールなどでしたらいったんCreateWindowExの第3引数は""として、直後でSetDlgItemIntを使うのが簡単です。
SetDlgItemIntはLong/DWord型の値で指定できます。
どちらもIntegerと同じく整数型なので、自動的に変換されます。

(あるいはStrPtr(Val())という手段もありますが)
ゲスト

#12 投稿記事 by ゲスト »

 イグトランス様、大変ありがとうございました。
 早速やってみましたが満足いく結果ではなかったので、ご報告させていただきます。
 まず教えていただいたStrPtr(Val())を引数にしたところ、"Val()が無効です"とメッセージが出てコンパイルできません。またSetDlgItemIntについてですが、使い方が分からなかったので付属のヘルプを見たところ、この名前ではトピックで見つかりませんでした。似た名前のSetDlgItemTextを試してみましたが、エラーは出ませんが何も入っていないようです。
 やっぱり無理なことをしようとしているんでしょうかね。
エイチ
記事: 8
登録日時: 2005年10月16日(日) 22:57
お住まい: 神奈川県厚木市

#13 投稿記事 by エイチ »

ごめんなさい。ログインしてませんでした。
イグトランス
記事: 899
登録日時: 2005年5月31日(火) 17:59
お住まい: 東京都
連絡する:

#14 投稿記事 by イグトランス »

すいません。Valではなく、Str$でした。
Str$は数値を文字列に変換する関数で、Valは文字列を数値にする関数です。
たとえばそのInteger型の変数が x ならStrPtr(Str$(x))とします。
これをCreateWindowExの第3引数に指定します。

SetDlgItemIntは自分でソースに宣言を置く必要があります。
プロジェクトのソースのどこかにこれを書いてください。
Declare Function SetDlgItemInt Lib "User32" (
hDlg As HWND,
nIDDlgItem As Long,
uValue As DWord,
bSigned As Long) As Long
使い方は1番目、2番目の引数はSetDlgItemTextと同じです。
3番目にコントロールに表示させたい数値を指定して、4番目はTRUEを指定してみてください。
エイチ
記事: 8
登録日時: 2005年10月16日(日) 22:57
お住まい: 神奈川県厚木市

#15 投稿記事 by エイチ »

 イグトランス様、どうもありがとうございました。
 早速やってみました。しかし...。Str$を使い***.abp(**) - "Str$(year)" 無効な識別子です となってしまいます。またSetDlgItemIntですが、やってみたところコンパイルエラーにはなりませんが、EDITBOXに何も入ってきません。
どうしてなのでしょうか?
返信する