반응형

* DateTime Class 를 이용한 현재 선택된 달의 마지막 날짜 및 요일 구하기 예제...

 

메인화면

 

전체 소스 코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CSharp_MonthLastDay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            numYear.Value = DateTime.Now.Year;
            numMonth.Value = DateTime.Now.Month;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //날짜 타입으로 변환 하기...
            DateTime dtTmp = DateTime.Parse(numYear.Value.ToString() + "-" + numMonth.Value.ToString() + "-01");
            //현재 선택된 달 + 1 하기...
            DateTime dt = dtTmp.AddMonths(1);
            //+1 된 달에서 하루 빼기...
            dt = dt.AddDays(-1);

            label4.Text = "선택된 년월: " + numYear.Value.ToString() + "-" + numMonth.Value.ToString();
            label5.Text = "마지막 일: " + dt.ToString("dd");
            label6.Text = "마지막 요일: " + GetDayOfWeek(dt);
        }

        //요일 String 문자열로 리턴 함수...
        private string GetDayOfWeek(DateTime dt)
        {
            string strDay = "";

            switch (dt.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    strDay = "월요일";
                    break;
                case DayOfWeek.Tuesday:
                    strDay = "화요일";
                    break;
                case DayOfWeek.Wednesday:
                    strDay = "수요일";
                    break;
                case DayOfWeek.Thursday:
                    strDay = "목요일";
                    break;
                case DayOfWeek.Friday:
                    strDay = "금요일";
                    break;
                case DayOfWeek.Saturday:
                    strDay = "토요일";
                    break;
                case DayOfWeek.Sunday:
                    strDay = "일요일";
                    break;
            }

            return strDay;
        }


    }
}

 

* 사용자 정의 함수 GetDayOfWeek => 요일 값을 문자열로 변환 하여 리턴 하는 함수

 

 

* 예제 결과

 

결과 화면

 

 

반응형
반응형

 

* 기존 프로젝트 불러 올 시

- 상위 버전 프로젝트 시 오류

: IDE VERSION 오류, gradle 오류

스튜디오 버전 3.0 이상 필요

This Gradle plugin requires a newer IDE able to request IDE model level 3.

For Android Studio this means version 3.0+

 

-> 상위 버전 프로젝트 설치 및 SDK 매너져에서 SDK 버전에 맞게 설치

- 프로젝트 폴더 이름이 한글이 들어간 경우 오류가 남.

반응형
반응형

* 안드로이드 스튜디오 빌드 후 휴대폰으로 APK Install apk 시 오류

 

메시지 박스 하나 뜨고 기존에 있던 프로젝트를 삭제 하겠냐고 물어 보고 YES 하면 삭제가 안되고  실패 에러 메시지가 delete_failed_internal_error error while installing apks~  나오는 경우

 

* 안드로이드 휴대폰에 직접 테스트 시 Run 을 하고 난 뒤 다시 Run 할 때 발생 하는 오류

 -> 해결 방법 -> 안드로이드 스튜디오 File -> Settings ->

     왼쪽 트리뷰에 Build, Execution, Deployment 메뉴 클릭 ->Instant Run 클릭 후 ->

     오른쪽 화면에 표시되는 곳 에서 Enable Instant Run to hot swap code/resource changes on deploy

     체크 되어 있는 것을 해제 후 Apply 버튼 클릭

 

반응형
반응형

* string 문자열을 정수 및 실수 형으로 변환 하기 예제...

 

메인 화면

전체 소스코드

Form1.vb

 

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'int 형으로 변환

        Dim iReturnValue As Integer = IsInt(textBox1.Text)

        If iReturnValue = 0 Then
            label1.Text = "int 형 변환으로 실패..."
            Return
        End If

        label1.Text = "int 형 변환 성공..."

    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        'Double 형으로 변환
        Dim dbReturnValue As Double = IsDouble(textBox1.Text)

        If dbReturnValue = 0 Then
            label1.Text = "Double 형 변환으로 실패..."
            Return

        End If

        label1.Text = "Double 형 변환 성공..."

    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
        'String 값 null 체크 및 빈 값 체크
        If IsNullString(textBox1.Text) Then
            label1.Text = "string 값이 Null 또는 빈 값입니다..."
            Return
        End If

        label1.Text = "string 값이 정상적입니다..."

    End Sub

    Private Function IsInt(ByVal ob As Object) As Integer

        If ob Is Nothing Then Return 0

        Dim i As Integer
        'int 형 변환
        Dim b As Boolean = Integer.TryParse(ob.ToString(), i)

        If Not b Then Return 0

        Return i

    End Function

    Private Function IsDouble(ByVal ob As Object) As Double

        If ob Is Nothing Then Return 0

        Dim db As Double
        'double 형 변환
        Dim b As Boolean = Double.TryParse(ob.ToString(), db)

        If Not b Then Return 0

        Return db

    End Function

    Private Function IsNullString(ByVal strTmp As String) As Boolean
        Return String.IsNullOrEmpty(strTmp)
    End Function

End Class

위 그림과 같이 int.TryParse 사용으로 오류없이 자연스럽게 형 변환 하는 모습입니다.

물론 Convert.ToInt32 () 로 가능 하며, int.Parse 로도 가능 하지만 예기치 못한 string 값에

 

숫자가 아닌 다른 문자열이 들어 가게 된다면... try~ catch~ 문이 없다면 오류를 내면서 프로그램

이 비정상적으로 종료 되는 걸 볼 수 있습니다.

 

 

int 형으로 변환 실패 된 그림 예 입니다. 만약 int.Parse 와 Convert.ToInt32 로 변환 하였다면

아래의 그림과 같이 오류 메시지가 뜨게 됩니다.

 

Double 형 변환 또한 int 형 변환 설명 드렸듯이 같습니다. 

형 변환 성공
형 변환 실패

마지막으로 string.IsNullOrEmpty() 함수로 string 문자열이 빈 값 인지 또는 null 값 인지 체크 하는 예 입니다.

 




https://kdsoft-zeros.tistory.com/76

 

[C#] string 을 int 및 double 형으로 변환 하기, null 체크

* string 문자열을 정수 및 실수 형으로 변환 하기 예제... 전체 소스코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;..

kdsoft-zeros.tistory.com

 

반응형
반응형

* string 문자열을 정수 및 실수 형으로 변환 하기 예제...

 

메인화면

전체 소스코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CSharp_getType
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //int 형 변환
            int iReturnValue = IsInt(textBox1.Text);

            if (iReturnValue == 0)
            {
                label1.Text = "int 형 변환으로 실패...";
                return;
            }

            label1.Text = "int 형 변환 성공...";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //double 형변환
            double dbReturnValue = IsDouble(textBox1.Text);

            if (dbReturnValue == 0)
            {
                label1.Text = "Double 형 변환으로 실패...";
                return;
            }

            label1.Text = "Double 형 변환 성공...";

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //string 값 체크
            //string str = null;
            if (IsNullString(textBox1.Text))
            {
                label1.Text = "string 값이 Null 또는 빈 값입니다...";
                return;
            }

            label1.Text = "string 값이 정상적입니다...";
        }


        private int IsInt(object ob)
        {
            if (ob == null) return 0;

            int iCheck = 0;
            bool bCheck = int.TryParse(ob.ToString(), out iCheck);

            if (!bCheck)
            {
                return 0;
            }

            return iCheck;
        }

        private double IsDouble(object ob)
        {
            if (ob == null) return 0;

            double  dbCheck = 0;
            bool bCheck = double.TryParse(ob.ToString(), out dbCheck);

            if (!bCheck)
            {
                return 0;
            }

            return dbCheck;
        }

        private bool IsNullString(string str)
        {
            return string.IsNullOrEmpty(str);
        }

    }
}

위 그림과 같이 int.TryParse 사용으로 오류없이 자연스럽게 형 변환 하는 모습입니다.

물론 Convert.ToInt32 () 로 가능 하며, int.Parse 로도 가능 하지만 예기치 못한 string 값에

숫자가 아닌 다른 문자열이 들어 가게 된다면... try{} catch{} 문이 없다면 오류를 내면서 프로그램

이 비정상적으로 종료 되는 걸 볼 수 있습니다.

 

int 형으로 변환 실패 된 그림 예 입니다. 만약 int.Parse 와 Convert.ToInt32 로 변환 하였다면

아래의 그림과 같이 오류 메시지가 뜨게 됩니다.

 

Double 형 변환 또한 int 형 변환 설명 드렸듯이 같습니다. 

 

형변환 성공
형 변환 실패

마지막으로 string.IsNullOrEmpty() 함수로 string 문자열이 빈 값 인지 또는 null 값 인지 체크 하는 예 입니다.

 

반응형
반응형

1. Empty Activity 를 선택 하여 Activity를 추가 또는 생성.

2. 기본 Activity 에 TabHost 컨트롤 을 추가

3. 소스 코드 및 실행 화면.

 

 

 

 

package com.example.administrator.androidcontrolex;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TabHost;

public class TabViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_view);

        TabHost tb = (TabHost)findViewById(R.id.tbHost);   // 탭호스트 ID: thHost
        tb.setup();

        TabHost.TabSpec ts1 = tb.newTabSpec("Tab Spec1");   
        ts1.setContent(R.id.tab1);     //탭 컨텐츠 xml 상에 Tabhost->LinearLayout-> TabWidget->FrameLayout->LinearLayout해당
        ts1.setIndicator("TAB 1");     //탭 이름 
        tb.addTab(ts1);                //탭 추가

        TabHost.TabSpec ts2 = tb.newTabSpec("Tab Spec2");
        ts2.setContent(R.id.tab2);
        ts2.setIndicator("TAB 2");
        tb.addTab(ts2);

        TabHost.TabSpec ts3 = tb.newTabSpec("Tab Spec3");
        ts3.setContent(R.id.tab3);
        ts3.setIndicator("TAB 3");
        tb.addTab(ts3);

         //탭 클릭 이벤트...

         tb.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override
            public void onTabChanged(String tabId) {
                // TODO Auto-generated method stub
            }
         });


     }                                                           
}
반응형
반응형

* 아래와 같이 실행 하기전 에뮬레이터는 이미 켜져 있는 상태에서 실행 하여야 됨.

 

1. C:\Users\Administrator\AppData\Local\Android\Sdk\platform-tools

   환경 변수 등록.

   -> 내컴퓨터 속성 -> 고급 시스템 설정 -> 고급 탭 클릭 -> 환경 변수 버튼 클릭

   -> 시스템 변수 path 를 찾아 클릭 후 편집 버튼 위 Android SDK 폴더 경로를

       맨 마지막에 추가 해준다. 확인 버튼

2. 환경 변수 등록을 마쳤으면 첨부 파일 다운 후 cmd 또는 보조프로그램에 명령프롬

   프트 클릭 첨부된 파일 다운 받은 경로로 이동 ex) 바탕 화면에 다운을 받아 놨다면

   아래의 경로가 됨. 
   -> C:\Users\Administrator\Desktop>adb install hangulkeyboard.apk 를 눌러 엔터

       설치가 되고 Sucess 가 나오면 준비 완료

 

hangulkeyboard.apk
0.06MB

 

3. 안드로이드 에뮬레이터 에서 설정 

   -> 언어 및 키보드 설정에서 키보드 us 로 되어 있는 것을 한글 키보드로 바꿔 주면 됨.

 

 

반응형
반응형

* VBNET 응용 프로그램 재시작 예제...

 

메인 화면

전체 소스 코드

Form1.vb

 

Imports System.Runtime.InteropServices

Public Class Form1

#Region "INI File...관련"
    <DllImport("kernel32.dll", SetLastError:=True)> _
    Private Shared Function GetPrivateProfileString(ByVal lpAppName As String, _
                                ByVal lpKeyName As String, _
                                ByVal lpDefault As String, _
                                ByVal lpReturnedString As System.Text.StringBuilder, _
                                ByVal nSize As Integer, _
                                ByVal lpFileName As String) As Integer
    End Function

    <DllImport("kernel32.dll", SetLastError:=True)> _
    Private Shared Function WritePrivateProfileString(ByVal lpAppName As String, _
                            ByVal lpKeyName As String, _
                            ByVal lpString As String, _
                            ByVal lpFileName As String) As Boolean
    End Function

    Public Shared Function SetINI(ByVal strAppName As String, _
                           ByVal strKey As String, _
                           ByVal strValue As String, _
                           ByVal strFilePath As String) As Boolean
        SetINI = WritePrivateProfileString(strAppName, strKey, strValue, strFilePath)
    End Function
    Public Shared Function GetINI(ByVal strAppName As String, _
                           ByVal strKey As String, _
                           ByVal strValue As String, _
                           ByVal strFilePath As String) As String
        Dim strbTmp As System.Text.StringBuilder = New System.Text.StringBuilder(255)

        GetPrivateProfileString(strAppName, strKey, strValue, strbTmp, strbTmp.Capacity, strFilePath)

        GetINI = strbTmp.ToString()

    End Function

    Public Shared Function Create_INIFile(ByVal strPath As String, _
                                   ByVal strFileName As String) As Boolean
        '해당 파일이 있으면 그냥 나가기...
        ' System.IO.File.Exists(strPath + "\" + strFileName) 요렇게 해도 됨.
        If Dir(strPath & "\" & strFileName) <> "" Then
            Exit Function
        End If

        '해당 폴더가 없다면 만들기...
        If Not System.IO.Directory.Exists(strPath) Then
            System.IO.Directory.CreateDirectory(strPath)
        End If

        Try
            Using sw As System.IO.StreamWriter = New System.IO.StreamWriter(strPath & "\" & strFileName, False)
                sw.WriteLine(vbCrLf)
                sw.Flush()
                sw.Close()
            End Using
        Catch ex As Exception

            Return False
        End Try

        Return True
    End Function

#End Region

    Dim strINIPath As String = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\")) + "\INI"
    Dim iCount As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Create_INIFile(strINIPath, "ReStart.ini")

        label2.Text = GetINI("Restart_Info", "restart", "0", strINIPath + "\ReStart.ini")
        iCount = Convert.ToInt32(label2.Text)

    End Sub

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        '다시 시작 하기...
        iCount += 1
        SetINI("Restart_Info", "restart", iCount.ToString(), strINIPath + "\ReStart.ini")

        '프로그램 종료
        Application.Exit()

        '1초 뒤에...
        System.Threading.Thread.Sleep(1000)

        '1번째 방법...
        'Application.Restart()
        '2번째 방법...
        System.Diagnostics.Process.Start(Application.ExecutablePath)
    End Sub


End Class

 

 

* 예제 결과

 

 

 

https://kdsoft-zeros.tistory.com/33

 

[VBNET] INIFile Create & Read & Write Example

* INI 파일 예제 Form1.vb Imports System.Runtime.InteropServices Imports System.IO Imports System.Text Public Class Form1 '빌드되는 폴더 경로 가져오기... Dim strCheckFolder As String = Application.E..

kdsoft-zeros.tistory.com

 

 

https://kdsoft-zeros.tistory.com/72

 

[C#] 응용 프로그램 재시작 예제

* C# 프로그램 재시작 예제... 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using S..

kdsoft-zeros.tistory.com

 

반응형

+ Recent posts