• ベストアンサー

サンプルプログラムをコンパイルするとエラーがでる。

Visual C++ 2005 Express Editionを勉強中で、あるWEBサイトで紹介されていたサンプルプログラムhttp://homepage3.nifty.com/ishidate/vcpp05_3/vcpp05_3.htm を使って、コンボボックスやテキストボックスを配置して以下のコードを入力しました。 private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { double a=double::Parse(textBox1->text); double b=double::Parse(textBox2->text); int indexNumber=comboBox1->SelectedIndex; double c; switch(indexNumber){ case 0:c=a+b;break; case 1:c=a-b;break; case 2:c=a*b;break; case 3:c=a/b;break; } label1->text=c.ToString(); } private:System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e){ comboBox1->SelectedIndex=0; } コードを”デバッグなしで実行”で動かそうとすると以下のようなエラーメッセージが出力されました。 >C801.cpp 1>c:\mywork\felicareader_test\c801\c801\Form1.h(138) : error C2248: 'System::Windows::Forms::Control::text' : private メンバ (クラス 'System::Windows::Forms::Control' で宣言されている) にアクセスできません。 1> c:\mywork\felicareader_test\c801\c801\Form1.h(23) : 'System::Windows::Forms::Control::text' の宣言を確認してください。 1> c:\windows\microsoft.net\framework\v2.0.50727\system.windows.forms.dll : 'System::Windows::Forms::Control' の宣言を確認してください。 1>c:\mywork\felicareader_test\c801\c801\Form1.h(139) : error C2248: 'System::Windows::Forms::Control::text' : private メンバ (クラス 'System::Windows::Forms::Control' で宣言されている) にアクセスできません。 1> c:\mywork\felicareader_test\c801\c801\Form1.h(23) : 'System::Windows::Forms::Control::text' の宣言を確認してください。 1> c:\windows\microsoft.net\framework\v2.0.50727\system.windows.forms.dll : 'System::Windows::Forms::Control' の宣言を確認してください。 1>c:\mywork\felicareader_test\c801\c801\Form1.h(148) : error C2248: 'System::Windows::Forms::Control::text' : private メンバ (クラス 'System::Windows::Forms::Control' で宣言されている) にアクセスできません。 1> c:\mywork\felicareader_test\c801\c801\Form1.h(23) : 'System::Windows::Forms::Control::text' の宣言を確認してください。 1> c:\windows\microsoft.net\framework\v2.0.50727\system.windows.forms.dll : 'System::Windows::Forms::Control' の宣言を確認してください。 1>ビルドログは "file://c:\mywork\felicareader_test\C801\C801\Debug\BuildLog.htm" に保存されました。 1>C801 - エラー 3、警告 0 ========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ========== エラーが3つでて、それをダブルクリックしてみると、どうやら、 ・double a=double::Parse(textBox1->text); ・double b=double::Parse(textBox2->text); ・label1->text=c.ToString(); この3つの文に問題があるということらしいのですが、原因がよくわかりません。 この原因わかるかたいらっしゃいましたらぜひご教授よろしくお願いいたします。

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

単に大文字になっていないだけとか。 C++言語は大文字と小文字を区別しますので、 int text; int Text; は別のものです。

maeken0012
質問者

お礼

回答ありがとうございます。 解決しました。

全文を見る
すると、全ての回答が全文表示されます。

その他の回答 (1)

  • redfox63
  • ベストアンサー率71% (1325/1856)
回答No.2

外部に公開しているのは『Text』だと思いますよ T(大文字) + ext(小文字)になります すべてが小文字のtextはコントロール内部で処理に利用しているものですので 外部から直接いじることは出来ません

maeken0012
質問者

お礼

回答ありがとうございます。 解決しました。以後気をつけます。

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • 入門サイトのサンプルプログラムがビルド出来ません

    こちらのサイトの http://www5b.biglobe.ne.jp/~suugaku/vc++kougi/kiso/dai1koudai7wa.html サンプルを作成してビルドしてみたのですが、 error C2248: 'System::Windows::Forms::Control::x' : private メンバ (クラス 'System::Windows::Forms::Control' で宣言されている) にアクセスできません。 'System::Windows::Forms::Control::x' の宣言を確認してください。 といったエラーがたくさん(100以上)出てビルドできません。 コピペなので入力誤りはないと思うのですが、何がいけないのでしょうか?

  • フォームのテキストコントロールへの出力

    Cは分かりますが、C++初心者です。 よろしくお願いします。 namespace sample1 外にある関数から、フォームのコントロールにアクセスするには、 どうしたらいいのでしょうか? ========================================================== #pragma once void DspData( ReadData *readdata ); //コールバック関数宣言 namespace sample1 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public __gc class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); } protected: void Dispose(Boolean disposing) { if (disposing && components) { components->Dispose(); } __super::Dispose(disposing); } private: System::Windows::Forms::Label * label1; private: System::Windows::Forms::Button * start; private: System::Windows::Forms::Button * end; public: System::Windows::Forms::TextBox * textBox1; private: System::ComponentModel::Container * components; void InitializeComponent(void) { } private: System::Void start_Click(System::Object * sender, System::EventArgs * e) { } }; } //------------------------------------------------ // DspData //------------------------------------------------ void DspData( ReadData *readdata ) { //***↓ここでフォームのテキストボックスへの表示を行いたい。***** textBox1->set_text("ここで出力") return; } ==========================================================

  • VC++2010について

    Windowsフォームアプリケーションを勉強し始めています。 Formに表示するだけの簡単なプログラムを打ち込んでみたのですが、ソリューションのビルドをしてみると、次のような2つのエラーが出ました。(実際にはもう一つあるのですが、それはintからfloatに変換されているというだけ) C1003.cpp(6): error C2143: 構文エラー : ';' が 'using' の前にありません。 C1003.cpp(19): fatal error C1075: 左側 中かっこ '{' に対応するものが 'g:\admin\visual studio 2010\projects\vc石立\c1003\c1003\Form1.h(3)' で見つかる前に EOF が検出されました。 こちらが入力したのは、Formに関するプログラムだけで、メインプログラム(.cpp)は一切変更してません。また、簡単なプログラムを何個か打ち込んでみたのですが、同じ二つのエラーが出ます。Formに関するプログラムの記述が間違ってるとも思えません。 その上、usingの前の行に” ; ”を入れてやると、一つ目のエラーは消えました(その前はinclude文)。おまけに、メインプログラムの最後の行(19行目)に” } ”を入れると、二つ目のエラーも消え、正常にビルドされ、デバックもできました。 解決はしたのですが、キツネにつままれたようです。いざ、無料でVCが手に入ると聞きつけ、喜び勇んで勉強しだしたのに…これからも同じ修正をしなくちゃと思うと、うんざりです。 コンソールアプリケーションは、問題なく動きます。 何か、心当たりのある方はいませんか? なお、打ち込んだのは、次の命令(2行目から)だけです。 #pragma endregion private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { double a=double::Parse(textBox1->Text); double b=double::Parse(textBox2->Text); int iNum=comboBox1->SelectedIndex; double c; switch(iNum){ case 0:c=a+b;break; case 1:c=a-b;break; case 2:c=a*b;break; case 3:c=a/b;break; }

  • C#のtextBox1への書込に関する質問

    C#(VS2013)のtextBox1への書込に関する質問です。 『textBox1.Text=str;』による、textBox1の書き込みは、『button1_Click』 の中から、直接『//write_textBox1("aaa"); 』を実行すれば出来ます。 しかし、Class1のtestを介して、『write_textBox1("bbb");』を実行した場合には textBox1に表示が出来ません。 尚、Consoleには、何れの場合にも表示出来ます。 Q1)Class1のtestを介して、textBox1への表示は可能ですか? =========== using System; using System.Windows.Forms; namespace TT_SendMessage { public partial class Form1:Form { public Form1() { InitializeComponent(); } public void write_textBox1(string str){ textBox1.Text=str; Console.WriteLine("VVVVVVVVVVVVVv"); } private void button1_Click(object sender,EventArgs e) { Class1 obj=new Class1(); obj.test(); //write_textBox1("aaa"); //<---この場合は、表示が出来る } }// public partial class Form1:Form { class Class1 { public void test() { bbb(); } public void bbb() { Form1 obj=new Form1(); obj.write_textBox1("bbb"); } }//class Class1 { } =============== 以上、宜しくお願いします。

  • 別スレッドからメインスレッドのテキストボックスに文字を表示させたい

    Visual C++ 2005 Express Editionを使用している初心者です。 タイトルの方法がどうしてもわからないので教えてください。 うまく説明できないので聞きたいところのコードを載せます。 //SAMPLE.cpp #include "stdafx.h" #include "Form1.h" using namespace SAMPLE; int main(array<System::String ^> ^args) { Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); Application::Run(gcnew Form1()); } //Form1.h #include <process.h> #include <vcclr.h> namespace SAMPLE { unsigned __stdcall counter(void *arg); int thread_id1; unsigned dummy; using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; public ref class Form1 : public System::Windows::Forms::Form { public:Form1(void) { InitializeComponent(); //別スレッド起動 thread_id1=_beginthreadex(NULL,0,counter,(void *)1,0,&dummy); } private: System::Windows::Forms::TextBox^ textBox1; private: System::ComponentModel::Container ^components; void InitializeComponent(void) { this->textBox1 = (gcnew System::Windows::Forms::TextBox()); //省略(コンポーネント初期化) } private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { } }; unsigned __stdcall counter(void *arg){ //別スレッド //ここで文字列を記述して上のtextBox1に表示したい return 0; } } 初歩的なことかもしれませんが、 よろしくお願いします。

  • C#

    form2で入力した文字を form1で表示させたいのですが、上手くいきません。プログラムの(文字制限の為)一部だけ のせます。アドバイス よろしくお願いします。 まず、form1 public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.Label label1; private Form2 form2; /// <summary> /// 必要なデザイナ変数です。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows フォーム デザイナ サポートに必要です。 // InitializeComponent(); form2= new Form2(); label1.Text=string.Format("{0}",form2.s); // // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。 // } static void Main() { Application.Run(new Form1()); } private void menuItem2_Click(object sender, System.EventArgs e) { if (form2.ShowDialog(this) == DialogResult.OK) this.Refresh(); } } 次にform2です private void button1_Click(object sender, System.EventArgs e) { string s; s=(string)textBox1.Text; } public string s { get { return s; } }

  • DLLサンプルプログラムが動きません

    Delphi XE5 starter で、 http://www39.atwiki.jp/kgh07155/pages/28.html を参考にして以下のようなプログラムを作りました。 コンパイルはできたのですが、Button1をクリックすると「TDllFormリソースが見つかりません」というエラーメッセージが出ます。 どういう風に修正すればいいのでしょうか? //***************************** //SamoleUnit2.pasの内容 unit Unit_Sample2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.dfm} function ShowDLLForm(hOwner: HWND): TModalResult; stdcall; external 'DLLSample.dll'; procedure ShowDLLForm2; external 'DLLSample.dll'; // ここまで、DLLを呼び出すための記述。 procedure TForm1.Button1Click(Sender: TObject); begin ShowDLLForm(Application.Handle); // DLL側でフォームを作成した後、 // 通常のフォームのShowModalメソッドと同じ動作をして // 作成したフォームを破棄。 end; procedure TForm1.Button2Click(Sender: TObject); begin ShowDLLForm2; // DLL側でフォームを作成した後、 // 作成したフォームを表示。 end; end. //******************************** //DllSample.dprの内容 library DLLSample; uses System.SysUtils, System.Classes, Windows, Forms, Controls, Unit_DLLForm in 'Unit_DLLForm.pas' {Form1}, Unit_Sample2 in 'Unit_Sample2.pas' {Form2}; type TDllForm = class(TForm) end; {$R *.res} function ShowDLLForm(hOwner: HWND): TModalResult; stdcall; var DllForm:TDllForm; begin Application.Handle := hOwner; // 呼び出し元の情報をDLL側が受け取る。 DllForm := TDllForm.Create(Application); // DLL側でフォームを作成する。 // フォームに配置された各オブジェクトも、自動で作成される。 Result := DllForm.ShowModal; // 返し値を設定。 DllForm.Free; // DLL側で作成したフォームを破棄。 Application.Handle := 0; // 呼び出し元の情報を破棄。 end; procedure ShowDLLForm2; var DllForm:TDllForm; begin DllForm := TDllForm.Create(Application); // DLL側でフォームを作成する。 DllForm.Show; // 作成したフォームを表示。 end; exports ShowDLLForm, ShowDLLForm2; begin end. //******************************** //unit_DLLForm.pasの内容 unit Unit_DLLForm; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.dfm} end.

  • VC++ TextBoxの定義

    お世話になります。 c++でTextBoxの入力制限(数値のみ)を、下記URLを参考に作成しているのですが、 TextBoxの動作を定義するところが、コンパイルエラーになります。 http://dobon.net/vb/dotnet/control/numerictextbox.html 【エラーになる定義部】 this->TextBox->KeyPress += System::Windows::Forms::KeyEventHandler(this, &MainForm::KeyPressEventArgs); ※ エラー内容は「XXXはYYYのメンバではありません」 「system::」のところか「&MainForm」のところの定義が悪いのだと思うのですが、 どの様に宣言すればよいのか教えていただけないでしょうか 【関数】 System::Void TextBox_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { 本文 }

  • VBプログラム エラーが出ます

    Public Class Form1 Private number As Integer Private rows As Integer Private columns As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Not Integer.TryParse(TextBox1.Text, rows) OrElse _ Not Integer.TryParse(TextBox2.Text, columns) OrElse _ Not Integer.TryParse(TextBox3.Text, number) Then MessageBox.Show("数字で入力してください", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If Me.Bounds = New Rectangle(10, 10, 1300, 800) Dim cnt As Integer = 0 For k As Integer = 1 To number For i As Integer = 1 To rows For j As Integer = 1 To columns Dim tb As TextBox = New TextBox() cnt += 1 tb.Name = "tb" + cnt.ToString() Me.Controls.Add(tb) tb.Top = (i - 1) * 30 + 80 tb.Left = (j - 1) * 60 + 70 * (columns * (k - 1)) + 10 tb.Width = 50 Next Next Next End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim sum As Double Dim cnt As Integer = 0 For i As Integer = 1 To rows For j As Integer = 1 To columns Dim tb As TextBox = New TextBox() cnt += 1 : If cnt > rows * columns Then cnt = 1 tb.Name = "tbA" + cnt.ToString Me.Controls.Add(tb) tb.Top = (i - 1) * 30 + (80 + 40 * rows) tb.Left = (j - 1) * 60 + 10 tb.Width = 40 sum = 0 For k As Integer = 1 To number sum += Double.Parse(CType(Me.Controls("tb" + (cnt + (rows * columns * k-1))).ToString(), TextBox).Text)    エラー Next tb.Text = sum.ToString() Next Next End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Do Until Me.Controls.Count <= 6 For Each tbD As Object In Me.Controls If CType(tbD, Control).Name Like "tb*" Then Me.Controls. Remove(tbD) Next Loop End Sub End Class エラーと書いている箇所 どう直したらよいのでしょうか。 縮小変換しないで呼び出されるアクセス可能なitemがないためオーバーロードの解決に失敗しました と出ます。 あとwindowsの画面の大きさを入力される値が小さければ少し小さいwindowsになるように変えたいのですがどうしたよいのでしょう。

  • VBプログラムエラー

    Private number As Integer Private rows As Integer Private columns As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim form2 As New Form() ' Create a button to add to the new form. Dim button1 As New Button() ' Set text for the button. button1.Text = "Scrolled Button" ' Set the size of the button. button1.Size = New Size(1000, 800) ' Set the location of the button to be outside the form's client area. button1.Location = New Point(form2.Size.Width + 200, form2.Size.Height + 200) ' Add the button control to the new form. form2.Controls.Add(button1) ' Set the AutoScroll property to true to provide scrollbars. form2.AutoScroll = True ' Display the new form as a dialog box. form2.ShowDialog() If Not Integer.TryParse(TextBox1.Text, rows) OrElse _ Not Integer.TryParse(TextBox2.Text, columns) OrElse _ Not Integer.TryParse(TextBox3.Text, number) Then MessageBox.Show("数字で入力してください", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If Me.Bounds = New Rectangle(10, 10, 1300, 900) Dim cnt As Integer = 0 For k As Integer = 1 To number For i As Integer = 1 To rows For j As Integer = 1 To columns Dim tb As TextBox = New TextBox() cnt += 1 tb.Name = "tb" + cnt.ToString() Me.Controls.Add(tb) tb.Top = (i - 1) * 30 + 80 tb.Left = (j - 1) * 60 + 70 * (columns * (k - 1)) + 10 tb.Width = 50 Next Next Next End Sub スクロール画面を作成し、 そのスクロール画面上にボタンを1つ作り、 テキストボックスが出てくるようにしたいです。 どうすればできるのでしょうか 。 これはわかるところまで作成しています。